R
Robert Klemme
Stefan Kaes said: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
-- stefanI 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
["_values", "_code", "_val", "_bnd"]local_eval( {:x=>1}, "puts x" )
["_values", "_code", "_val", "_bnd", "x"]
nil
=> nil