From: Robert Klemme Date: 2005-03-16T19:49:48+09:00 Subject: Re: eval/binding question "Stefan Kaes" schrieb im Newsbeitrag news:4238013C.8040806@gmx.net... > Robert Klemme wrote: > > >Hm, I'm not 100% sure I modeled this properly, but does this solve the > >problem? > > > > > No. _code gets parsed on every call to local_eval. If you want to avoid that you'll need a two step approach. But then the var names are needed beforehand... Ok, I see the problem (finally) :-) Cheers robert > > >I omitted the template name and the value as these are just special cases > >of values with fixed names. But you get the picture. And there is no > >reparsing needed. > > > >def local_eval(_values, _code) > > _val = nil > > _bnd = binding > > p local_variables > > _values.each {|name, val| eval "#{name}=_val", _bnd} > > p local_variables > > eval _code, _bnd > >end > > > > > > > >>>local_eval( {:x=>1}, "puts x" ) > >>> > >>> > >["_values", "_code", "_val", "_bnd"] > >["_values", "_code", "_val", "_bnd", "x"] > >nil > >=> nil > > > > > -- stefan >