Skip to content

Instantly share code, notes, and snippets.

@kohsuke
Created May 31, 2012 15:26
Show Gist options
  • Select an option

  • Save kohsuke/2844148 to your computer and use it in GitHub Desktop.

Select an option

Save kohsuke/2844148 to your computer and use it in GitHub Desktop.
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