Skip to content

Instantly share code, notes, and snippets.

@subbuss
Created October 30, 2014 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subbuss/f7eca65c919776da854f to your computer and use it in GitHub Desktop.
Save subbuss/f7eca65c919776da854f to your computer and use it in GitHub Desktop.
[subbu@earth /tmp] cat y.rb
require 'x'
C.boo
eval 'p x', TOPLEVEL_BINDING
[subbu@earth /tmp]
[subbu@earth /tmp] cat x.rb
x = 1
p "--1--"
eval "p x"
def foo
p "--2--"
eval "p x", TOPLEVEL_BINDING
end
foo
class C
class << self
p "--3--"
eval "p x", TOPLEVEL_BINDING
end
end
[subbu@earth /tmp] cat y.rb
require 'x'
C.boo
eval 'p x', TOPLEVEL_BINDING
[subbu@earth /tmp] mri -I. y.rb
"--1--"
1
"--2--"
<main>:in `<main>': undefined local variable or method `x' for main:Object (NameError)
from /tmp/x.rb:7:in `eval'
from /tmp/x.rb:7:in `foo'
from /tmp/x.rb:10:in `<top (required)>'
from /home/subbu/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.2.0/rubygems/custom_require.rb:36:in `require'
from /home/subbu/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.2.0/rubygems/custom_require.rb:36:in `require'
from y.rb:1:in `<main>'
[subbu@earth /tmp] jruby -X-C -I. y.rb
"--1--"
1
"--2--"
NameError: undefined local variable or method `x' for main:Object
foo at :1
eval at org/jruby/RubyKernel.java:962
foo at /tmp/x.rb:7
(root) at /tmp/x.rb:10
require at org/jruby/RubyKernel.java:926
(root) at /home/subbu/jruby/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1
require at /home/subbu/jruby/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:55
[subbu@earth /tmp]
[subbu@earth /tmp] jruby -X-C -I. x.rb
"--1--"
1
"--2--"
1
"--3--"
1
[subbu@earth /tmp] mri -I. x.rb
"--1--"
1
"--2--"
1
"--3--"
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment