I’ve become frustrated writing a bunch of [:
hash = {:foo => 'bar'} # so ugly... => {:foo=>"bar"} hash[:foo] # again... => "bar"
Sure there’s the openstruct thingy but it’s completely useless.
So i’ve gone against the rules and extended Hash, ending up in a dangerous (choose keys wisely) but so much more confortable syntax:
class Hash def method_missing(m) k = m.to_sym return self[k] if self.has_key? k super end end
In action:
hash = {foo: 'bar'} => {:foo=>"bar"} hash.foo => "bar"