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