title: Access local variables from a different binding in Ruby
body: <p>In Ruby, you can easily access local variables programmatically by using <code>local_variables</code> and <code>eval</code>. I would really like to have meta-programming access to these variables using a single method call such as</p>
  
  <pre><code># define a variable in this scope, such as
  x = 5
  Foo.explore_locals  # inside the Foo#explore_locals method, access x
  </code></pre>
  
  <p>where <code>Foo</code> is some external module. The idea is to display and export local variables in a nice way.</p>
  
  <p>What should be inside the <code>explore_locals</code> method? Is there any way to make this possible? If absolutely necessary, I guess it could be</p>
  
  <pre><code>Foo.explore_locals binding
  </code></pre>
  
  <p>but this is much less elegant for the application I have in mind.</p>