From: Robert Klemme Date: 2008-01-10T03:29:58+09:00 Subject: Re: struct equivalent with rails-y keyword args hash? On 09.01.2008 19:13, Giles Bowkett wrote: > several good suggestions but I think this is the one I'll run with: > >> Second one, method for all Structs: >> >> manveru@pi ~ % irb >> class Struct >> def self.create(hash) >> new(*hash.values_at(*members.map{|m| m.to_sym})) >> end >> end >> # nil >> Note = Struct.new(:channel, :note, :duration, :velocity, :time) >> # Note >> Note.create(:channel => 1, :note => 2, :duration => 3, :velocity => 3, >> :time => Time.now) >> # #> Jan 09 14:37:20 +0900 2008> > > Ara's seems the most robust, but with so much going on and no specs it > makes me antsy; the OpenStruct looks good too but I want classes as > well as instances. > Folks, why do you run around implementing something? The desired behavior *is already present* with Struct. Cheers robert