Created
March 19, 2013 01:11
-
-
Save bxt/5192713 to your computer and use it in GitHub Desktop.
Monkey-patches the methods transform into ruby's Hash class to allow easy mapping of hash values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Hash | |
| def transform | |
| inject(self.class.new){|acc, (k, v)| acc[k] = yield(v); acc } | |
| end | |
| def transform! | |
| each{|k,v| self[k]=yield(v)} | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment