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
=> 1>> o.b = 2
=> 2>> o.h = OpenHash.new
=> {}>> o.h.a = 1
=> 1>> o.h.b = 2
=> 2>> pp o
{:a=>1, :b=>2, :h=>{:a=>1, :b=>2}}
=> nil
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---