From: Clemens Hintze Date: 2001-10-23T16:03:45+09:00 Subject: [ruby-talk:23022] Re: assigning variables Joseph McDonald wrote: > > HEF> One problem, I think, is that eval can't create a > HEF> new local variable. (It can, but only within the > HEF> context of the eval -- it won't be defined when > HEF> you return.) > > Doh! That definitely sinks my idea. bummer. I did get it to work > with instance variables which I think will do. Hmm ... is this what you want to do? def setvars(vars, bind) vars.each do |k,v| $helper = v eval "#{k} = $helper", bind end end a,b = nil,nil v = {'a' => 12, 'b' => [9,8,7]} setvars v, binding p a #-> 12 p b #-> [9, 8, 7] Unfortunately you need a global helper and for Ruby to know 'a' and 'b' are variables, Ruby has to see assignment before HTH, \cle