From: Stefan Kaes Date: 2005-03-16T18:50:07+09:00 Subject: Re: eval/binding question --------------060409080004040409060302 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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. >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 --------------060409080004040409060302--