Ruby: change each value in a hash with something like #collect for arrays?
- by Adam Nonymous
Hi!
I'd like to replace each value in a hash with value.some_method.
For example in a simple hash {"a" = "b", "c" = "d"} every value should be .upcase-d so it looks like {"a" = "B", "c" = "D"}.
I tried #collect and #map but always just get arrays back. Is there an 'elegant' way to do this?
Thanks in advance,
Adam Nonymous
UPDATE: Damn, I forgot: The hash is in an instance variable which should not be changed. I need a new hash with the changed values, but would prefer not to define that variable explicitly and then loop over the hash filling it. Something like new_hash = hash.magic {...} ;)