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)
(God I wish I could configure bloody Gmail to use monospaced fonts.)
Anyway, is there an easy equivalent to Struct which, instead of taking
stuff in sequence, takes a Hash of options, in a Rails-y style? Like a
HashStruct? Does Facets have such a thing, maybe haps? If not, is the
basic code for Struct in Ruby, and/or is a class like Struct but with
Hashes easy to build?
–
Giles B.
Podcast: http://hollywoodgrit.blogspot.com
Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com