Pretty neat Mash class (Magic Hash)

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] = unless self[key] || value
return self[key]

Its like OpenStruct…so what can you do?

require ‘pp’
m =
m.first_name = “john”
m.last_name = “doe”
m.address.street = “somewhere drive” = “somecity”
m.address.state = “somestate” = 12334
pp m

:street=>“somewhere drive”,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs