class Mash < Hash
def method_missing(name, value=nil)
key = name.to_s.sub(/[=?!]$/,'''').to_sym
self[key] = value if name.to_s[-1,1] == "="
self[key] = Mash.new unless self[key] || value
return self[key]
end
end
Its like OpenStruct...so what can you do?
require ''pp''
m = Mash.new
m.first_name = "john"
m.last_name = "doe"
m.address.street = "somewhere drive"
m.address.city = "somecity"
m.address.state = "somestate"
m.address.zip = 12334
pp m
{:address=>
{:state=>"somestate",
:street=>"somewhere drive",
:city=>"somecity",
:zip=>12334},
:first_name=>"john",
:last_name=>"doe"}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---