I love OpenStruct, but it has no ability to iterate over the members.
I had extended it, but recently I use this little class. Anyone see
any issues with it ?
class OpenHash < Hash
def method_missing(name, value=nil)
key = name.to_s.sub(/[=?!]$/,’’).to_sym
self[key] = value if name.to_s[-1,1] == “=”
return self[key]
end
end
o = OpenHash.new
=> {}o.a = 1
=> 1o.b = 2
=> 2o.h = OpenHash.new
=> {}o.h.a = 1
=> 1o.h.b = 2
=> 2pp o
{:a=>1, :b=>2, :h=>{:a=>1, :b=>2}}
=> nil