Todd Benson
9/21/2008 2:55:00 AM
On Sat, Sep 20, 2008 at 6:59 PM, Jason Lillywhite
<jason.lillywhite@gmail.com> wrote:
> I just saw a similar issue (#163350 of this forum).
>
> seems like this might work to change values of a hash:
>
> hash = {'x'=>2, 'y'=5}
> hash_new = hash.inject({}) do |h, (k,v)|
> h[v * 2] = k
> h
> end
>
> although this returns {10=>"y", 4=>"x"}
With your example...
h = Hash['x', 2, 'y', 5]
h.each_key {|k| h[k] *= 2}
Todd