From: Kristof Bastiaensen Date: 2004-05-01T21:34:02+09:00 Subject: Re: def [](v) xx; return yy; end # returned value is ignored !? Hi, On Sat, 01 May 2004 21:07:57 +0900, Jean-Hugues ROBERT wrote: >>It may be interesting to be able to access variables indirectly >>using binding() (outside eval). >>for example: >> >>a = 2 >>binding().local_get(:a) >>=> a == 2 > > You can ! > eval( :a, binding()) ? > I would rather get rid of the eval, because eval has to recompile the statement, and I have the feeling it is not really part of the language (it is more like the language itself). From the point of a byte-code interpreter, the eval statement doesn't generate a bytecode, but will call a method that will do so. >>binding().local_set!(:a, 5) >>=> a == 5 > > eval( "a = 5") or > tmp = arbitrary_expr; eval( "a=tmp", binding()) The behaviour would be different if a is not set. Eval would raise an error, while local_get(:a) would just return nil.