From: John Sikora Date: 2010-10-07T04:08:55+09:00 Subject: Re: setting local variables in a binding Martin DeMello wrote: > Why does this not work? > > ruby-1.9.2-p0 > b = binding > => # > ruby-1.9.2-p0 > eval("x = 5", b) > => 5 > ruby-1.9.2-p0 > x > NameError: undefined local variable or method `x' for main:Object > from (irb):6 > from /home/martin/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `
' > ruby-1.9.2-p0 > eval("x") > NameError: undefined local variable or method `x' for main:Object > from (irb):7:in `eval' > from (irb):7:in `eval' > from (irb):7 > from /home/martin/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `
' > ruby-1.9.2-p0 > eval("x", b) > => 5 > > martin Hmmm, it seems to work when x is already defined (in 1.9.2): irb(main):001:0> x=4 => 4 irb(main):002:0> b=binding => # irb(main):003:0> eval("x=5", b) => 5 irb(main):004:0> x => 5 irb(main):005:0> If I do not set x to a value beforehand, I get the same error. Do not know why though. js -- Posted via http://www.ruby-forum.com/.