E
email55555 email55555
I have this example codes:
b = binding
['x', 'y'].each { |e| eval("#{e} = 123", b) }
p local_variables
p x
p y
Run the codes from irb, everything works.
However, save it to a file like pgm.rb and ruby it as "ruby pgm.rb", I
got the error message as:
["b", "x", "y"] #==> it does print the local_variables correctely.
pgm.rb:4: undefined local variable or method 'x' for main:Object (NameError)
Why? local_variables array does show me the "x", why it fail on "p x" ??
b = binding
['x', 'y'].each { |e| eval("#{e} = 123", b) }
p local_variables
p x
p y
Run the codes from irb, everything works.
However, save it to a file like pgm.rb and ruby it as "ruby pgm.rb", I
got the error message as:
["b", "x", "y"] #==> it does print the local_variables correctely.
pgm.rb:4: undefined local variable or method 'x' for main:Object (NameError)
Why? local_variables array does show me the "x", why it fail on "p x" ??