From: lasitha Date: 2009-03-12T15:07:43+09:00 Subject: Re: change (and update) values of hash On Thu, Mar 12, 2009 at 11:10 AM, Jason Lillywhite wrote: > how would I do stuff to each value of a hash and return a modified hash? > h = {"a"=> 3, "b"=> 5} > multiply each value by 2 and return > h = {"a"=> 6, "b"=> 10} One way (among several): $: irb 01> h = { 'a' => 3, 'b' => 5 } --> {"a"=>3, "b"=>5} 02> h.inject(h) {|h, (k, v)| h[k] = v * 2; h } --> {"a"=>6, "b"=>10} solidarity, lasitha.