From: James Gray Date: 2008-01-09T23:13:48+09:00 Subject: Re: struct equivalent with rails-y keyword args hash? On Jan 8, 2008, at 11:02 PM, Giles Bowkett wrote: > I have some code which uses Structs. I'd rather use keyword args. I'm > generating data objects to store MIDI note data, and it's kind of > hideously unreadable: > > Note.new(2, 43, 0.25, 127, now += interval) > > This would be much nicer: > > Note.new(:channel => 2, > :note => 43, > :duration => 0.25, > :velocity => 127, > :time => now += interval) One way is: require "ostruct" now = Time.now interval = 5 note = OpenStruct.new( :channel => 2, :note => 43, :duration => 0.25, :velocity => 127, :time => now + interval ) note.channel # => 2 note.velocity # => 127 __END__ James Edward Gray II