From: Lloyd Zusman Date: 2004-04-21T22:25:43+09:00 Subject: Re: Ruby proposal: MAIN_BINDING Szymon Drejewicz writes: > What do you think about MAIN_BINDING for use it with eval(): > > eval("a = 'hello'",MAIN_BINDING) > puts a > > outputs: > hello > > > ? Well, the following does work: a = 'goodbye' eval("a = 'hello'", binding()) puts a # => hello The reason has to do with the differing manner in which ruby interprets "puts a" in the presence and absence of a previous variable definition for "a". If "a" is previously defined as a variable, the compiler causes the "puts a" command to simply output its value; but if "a" is not previously defined, my understanding is that "puts a" interprets "a" as a method call. In this case, "eval" statement (whose command is not, of course, touched by the interpreter) indeed sets the "a" variable in the global scope, but the "print" statement doesn't access it. I'm don't know if there's a syntactical way around this. -- Lloyd Zusman ljz@asfast.com