Yukihiro Matsumoto <matz / ruby-lang.org> writes:
> Hi,
>
> In message "Re: Hash#rekey"
>     on Mon, 5 Feb 2007 03:08:15 +0900, "Trans" <transfire / gmail.com> writes:
>
> |> No.  "foo" and :foo are different keys in a hash.
> |
> |And never the twain shall meet? So it's long live
> |HashWithIndifferentAccess ?
>
> The HashWithIndifferentAccess behavior will not be default even after
> Ruby 2.0; that's for sure.
>
> |A while back I offered the idea of being able to define a key coerce
> |proc, eg.
> |
> |  h = Hash.new.key!{ |k| k.to_s }
> |
> |Such that keys would always be strings. Might someting like that be a
> |viable solution?
>
> Maybe, but not with a name like "key!".
>
> |In anycase, I still offer up #rekey.
>
> I don't think "rekey" represents the behavior well.  Any better name?
> transpose_keys comes to my mind.
>
> 							matz.

How about this?

  hsh.map! {|h,k,v| h[k.to_s] = v}

Or maybe a block argument to #rehash?

  h.rehash {|h,k,v| h[k.to_s] = v}

Instead of key!, #coerce_key_proc.

FYI, the word "rekey" has at least two common usages in (American?)
English.

  1. to transcribe a text again, using a keyboard
     "Due to poor image quality, the OCR output for those documents
      is unusable and we will have to rekey them."

  2. to reconfigure a lock so that it can be opened by a different
     key, and usually not be opened by the original key 
     "We hired a locksmith to rekey all of the doors in our new house."

Both are technically jargon, although (2) is pretty universal.  Both
are more common than "key" as a verb, I think.

I prefer Hash#map! or a block argument to #rehash.  It's more general
without being more expensive.

Steve