I am fiddling around with the eval() function, and loading information at 
runtime.  The following works as expected:

$> ruby -e 'str = "def foo; 10; end"; eval(str); puts foo+1'
11

However, why does this not work?

$>ruby -e 'str = "a = 2"; eval(str); puts a'
-e:1: undefined local variable or method `a' for #<Object:0x124b00> 
(NameError)

I know I can do something like 'bar = eval(str)' to get the value to which 
str evaluates to, but I was hoping it would remember the variable name, 
mostly because the string I am evaluating has more than one operation in it, 
and the assignment only captures the last.  Is this not possible?  Thanks.

Matt

p.s.  If I do the equivalent in IRB, it remembers the variable name.

irb(main):005:0> str = "a =2; b =3"
"a =2; b =3"
irb(main):006:0> eval(str)
3
irb(main):007:0> a
2
irb(main):008:0> b
3
irb(main):009:0>

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.  
http://join.msn.com/?page=features/virus