From: Robert Dober Date: 2006-11-13T00:22:26+09:00 Subject: Re: Create local variable in Binding after it's creation ------=_Part_95255_3979542.1163344943994 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 11/12/06, Mauricio Fernandez wrote: > > On Sun, Nov 12, 2006 at 11:06:44PM +0900, Christian Surlykke wrote: > > Is it possible to create a new local variable in a binding after it's > creation? > > You can create it, but you won't be able to use it directly. > > > Specifically, what I'd like to do: > > > > l = lambda { puts a } # 'a' not defined at this point. > > eval('a = 7', l.binding) # Hope to create a in l's binding > > l.call # Hope to get '7' > > l = lambda{ eval 'a' } > eval('a = 7', l.binding) > l.call # => 7 > eval('a') # => 7 > > If you try to use 'a' before the parser sees 'a = ...', it will be > considered > a method call, and you'll get a NameError even if you give it a value > afterwards/in eval. > > BTW. this is changing in 1.9. > > -- > Mauricio Fernandez - http://eigenclass.org - singular Ruby > > I do not want to argue with Mauricio, I know when I am outclassed(1), but maybe one should suggest a different approach to OP. Can you use instant variables, or will that be impacting elsewhere p = Proc.new { puts @a } @a= Guess what? p.call And yes Mauricio can you give a pointer to the new behavior please, thx. Cheers Robert (1) Well I do not, but that remains between us ;) -- The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man. - George Bernard Shaw ------=_Part_95255_3979542.1163344943994--