On Oct 30, 12:10=A0pm, shenry <stuarthe... / gmail.com> 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 =3D { :name =3D> "Joe", :age =3D> 50 }
>
> params =3D { "name" =3D> "Bill" }
>
> new_hash =3D default.merge(params)
>
> >> { :name =3D> "Joe", :age =3D> 50, "name" =3D> "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.
>
> Any help greatly appreciated.

  require 'facets/hash/rekey'

  default.merge(params.rekey)

rekey takes a block, without a block it is the same as:

  rekey(&:to_sym)