From: David Whetstone Date: 2009-08-11T07:16:57+09:00 Subject: Re: instance_variables vs. local_variables Joel VanderWerf wrote: > def get_empty_binding > binding > end > b = get_empty_binding > > eval("a=1", b) > p eval("a", b) # ==> 1 > > Not sure this is what you're looking for. This clears up a misperception I had when trying similar examples. For example, while your example works, the following does not: eval("a=1") p eval("a") # ==> NameError: undefined local variable or method ‘a’ for main:Object My incorrect assumption was that the object returned by Kernel::binding (implicitly called by eval when no binding is specified) represented the _actual_ bindings of the current context. But it's really only a copy, with each call to eval retrieving a fresh copy. In practice, this: eval("a=1") is roughly equivalent to this: do a = 1 end in that local symbols introduced inside are not accessible outside. So, there really is no way to affect the bindings of an existing context, since only a copy of the current bindings can ever be acquired. Looks like I'm sticking with method_missing. -- Posted via http://www.ruby-forum.com/.