-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 #upcase doesn't modify the receiver. #upcase! doesn't work because you can't modify String keys, as they are frozen. So, you have to rebuild the hash, the others pointed out some solutions for this. Regards, Florian Gilcher On Aug 20, 2008, at 7:34 PM, Brian Ross wrote: > How can I iterate through a hash so that each key is modified and > saved into > a new hash? > > # Beginning of code > > hash = {"name"=>"greg", "job"=>"boring", "hair"=>"plenty"} > p hash > > map = hash.each_key do |key| > key.upcase > end > > p map > > # End of code > > I'd imagine that this would return map as a new hash with the keys > modified. > Is there anything like collect! for hashes? > > Brian -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) iEYEARECAAYFAkisX3AACgkQJA/zY0IIRZYC0ACfVfK1H80uupfXn/g0jhp69uzB O4YAoMIao4OCp1WfSUkpTWKW3LQA3tKP =WHKL -----END PGP SIGNATURE-----