From: Robert Klemme Date: 2003-06-25T17:16:51+09:00 Subject: Re: Another Run Time Evaluation Q: "Orion Hunter" schrieb im Newsbeitrag news:BAY2-F7808xWI0AT2Jv00000db0@hotmail.com... > 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 # > (NameError) try this $>ruby -e 'str = "a = 2"; eval(str, binding); puts a' You need to give the current context for locals, otherwise eval creates its own scope. robert