From: Shashank Date Date: 2003-06-27T12:41:51+09:00 Subject: Re: Another Run Time Evaluation Q: "ts" wrote in message > irb do someting like this > > svg% ruby -e 'eval("a=2"); eval("puts a")' > 2 Oh, I see. > 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' Got it ! Thanks for taking time to explain this in detail. > Guy Decoux >