From: Daniel Schierbeck Date: 2006-06-15T20:24:37+09:00 Subject: Re: convert Dave Burt wrote: > Daniel Schierbeck wrote: >> Joakim Oman wrote: >>> Hello >>> >>> I wonder if there is a simple way to convert all keys in a Hash to >>> member variables in a Class without knowing the key names in the Hash >>> beforehand. >> vars = {:foo => 101, :bar => 42, :baz => 1337} >> vars.each do |name, value| >> SomeClass.instance_variable_set("@#{name}", value) >> end >> >> You could also use an OpenStruct. > > That won't work, because it doesn't create accessors. Ahh, didn't see the last part of the post! (Damn these trigger-happy fingers of mine!) Cheers, Daniel