From: Vassilis Rizopoulos Date: 2008-07-23T21:59:43+09:00 Subject: Re: Generate accessors for an hash Andrea Gianarro wrote: > Hello, I need to generate read and write accessors for all the keys in > an hash. > > Wouldn't a simpler solution be to use OpenStruct? require 'ostruct' hash={"my_attribute"=>"value"} s=OpenStruct.new(hash) puts s.my_attribute > value s.my_attribute="new" => "new" puts s.my_attribute > new => nil And you get the freebie of creating new keys from the setter: s.new_attribute="better" => "better" puts s.new_attribute > better Cheers, V.- -- http://www.braveworld.net/riva