From: Philip Mak Date: 2002-06-03T08:08:29+09:00 Subject: Re: $a = 5; $b = 'a'; print $$b On Mon, Jun 03, 2002 at 07:57:43AM +0900, Erik B�gfors wrote: > > class Series > > attr_accessor :sid, :handle, :name > > def initialize(vals) > > vals.each_key { |key| > > @(key) = vals[key] # This doesn't work; syntax error > > I don't understand what you are trying to do here. Basically, I want to do this: class Series attr_accessor :sid, :handle, :name def initialize(vals) @sid = vals['sid'] @handle = vals['handle'] @name = vals['name'] end end without having to type out the @x = vals['x'] line for each and every instance variable, since I have other classes that have a lot of variables. I tried eval(@key = vals[key]) and eval(@key) = vals[key] but those didn't evaluate correctly.