Created
May 31, 2012 15:26
-
-
Save kohsuke/2844148 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Foo | |
| def initialize | |
| @x=10 | |
| end | |
| end | |
| f = Foo.new | |
| i = 1 | |
| b = f.instance_eval do | |
| # this binding can see all members of f (like @x) as well as variables in the outer sopce (like i) | |
| binding | |
| end | |
| puts eval("@x",b) | |
| puts eval("f",b) | |
| puts eval("i",b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment