shenry wrote:
> I'm trying to merge to hashes, one using symbols as keys (the defined
> default values for my class) and the other using strings as keys
> (taken from the params hash).
> 
> default = { :name => "Joe", :age => 50 }
> 
> params = { "name" => "Bill" }
> 
> new_hash = default.merge(params)
>>> { :name => "Joe", :age => 50, "name" => "Bill }
> 
> What's the Ruby way to handle this so that it overwrites :name with
> "name"? Do I need to implement a stringify_keys or symbolize_keys
> method like in Rails? I'd like to avoid using strings as the keys in
> my default hash.

I would think it would be easiest to use something like symbolize_keys. 
Or just lift the whole HashWithIndifferentAccess class from Rails.

> 
> Any help greatly appreciated.
> 
> Stu

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen / marnen.org
-- 
Posted via http://www.ruby-forum.com/.