>>>>> "S" == Shashank Date <sdate / everestkc.net> writes:

S> "ts" <decoux / moulon.inra.fr> wrote in message
>> svg% ruby -ve 'a=nil; str = "a=2"; eval(str,binding); puts a'
S>                            ^^^^
S> Of course, by creating 'a' here, this has to work. I would like
S> to know how irb can make it work without pre-creation of  "a".

 irb do someting like this

svg% ruby -e 'eval("a=2"); eval("puts a")'
2
svg% 


 My example work not because the variable was created before the eval, but
 because ruby has seen *at compile time* that `a' is a variable.

 If you write

   ruby -ve 'str = "a=2"; eval(str,binding); puts a'

 at compile time, `puts a' is interpreted as a method call, i.e. `puts a()'

 Now with

   ruby -ve 'a = nil; str = "a=2"; eval(str,binding); puts a'

 when ruby compile the script, it see that `a' is a local variable and 
 `puts a' is interpreted as an access to the local variable `a'


Guy Decoux