Skip to content

Instantly share code, notes, and snippets.

@shugo
Created November 29, 2011 06:47
Show Gist options
  • Save shugo/1403749 to your computer and use it in GitHub Desktop.
Save shugo/1403749 to your computer and use it in GitHub Desktop.
$ cat t.rb
b = eval("def get_binding; binding; end; get_binding",
TOPLEVEL_BINDING,
__FILE__,
__LINE__ - 3)
p eval(<<EOF, b)
def foo; end
self.foo
EOF
$ ~/ruby/1.9.2/bin/ruby-1.9.2 -v /tmp/t.rb
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
/tmp/t.rb:2:in `get_binding': private method `foo' called for main:Object (NoMethodError)
from /tmp/t.rb:5:in `eval'
from /tmp/t.rb:5:in `<main>'
$ ruby-trunk -v /tmp/t.rb
ruby 2.0.0dev (2011-11-29 trunk 33895) [i686-linux]
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment