Anything wrong with this? am I just making trouble?

I have included this extension to Hash in my rails app...

class 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

I basically lets a plane old Hash behave like the fancy OpenStruct, so you can do things like hash.amount = 10 instead of hash[:amount] = 10. It uses method_missing to do its stuff.

h = Hash.new

=> {}

h.a = 1

=> 1

h.b = 2

=> 2

h.c = 3

=> 3

pp h

{:a=>1, :b=>2, :c=>3} => nil

h.h = Hash.new

=> {}

h.h.a = 1

=> 1

h.h.b = 2

=> 2

h.h.c = 3

=> 3

pp h

{:a=>1, :b=>2, :c=>3, :h=>{:a=>1, :b=>2, :c=>3}} => nil

I have included this extension to Hash in my rails app...

class 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

I basically lets a plane old Hash behave like the fancy OpenStruct, so you can do things like hash.amount = 10 instead of hash[:amount] = 10. It uses method_missing to do its stuff.

I suppose the danger is that the day you do hash.delete_if! instead of
getting a no method error it will just work and lead to a less easy to
understand error further down the road.

Fred