2008/1/10, Robert Klemme <shortcutter / googlemail.com>: > On 09.01.2008 19:37, Giles Bowkett wrote: > >> Folks, why do you run around implementing something? The desired > >> behavior *is already present* with Struct. > > > > I tried your code example, and it didn't work. > > > > class Note < Struct.new(:channel) ; end > > > > Note.new(:channel => 2) > > Note.channel # => "{:channel => 2}" > > > > It just stores the hash. > > Argh!! You are right, I am wrong. I'm sorry, should have payed > attention more closely to the output of #inspect. I think I'll better > shut up now. Hm, could not resist... Here is another variant: Note = Struct.new(:channel, :note, :duration, :velocity, :time) do def self.create(hash) new(*members.map {|me| hash[me.to_sym]}) end end irb(main):016:0* now = interval = 1 => 1 irb(main):017:0> n = Note.new(:channel => 2, irb(main):018:1* :note => 43, irb(main):019:1* :duration => 0.25, irb(main):020:1* :velocity => 127, irb(main):021:1* :time => now += interval) => #<struct Note channel={:channel=>2, :note=>43, :duration=>0.25, :velocity=>127, :time=>2}, note=nil, duration=nil, ve locity=nil, time=nil> irb(main):022:0> :-) robert -- use.inject do |as, often| as.you_can - without end