Created
November 21, 2014 19:43
-
-
Save groeneman/c76bb7e6437923c15278 to your computer and use it in GitHub Desktop.
Hash#megamap
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 mega_map(key_transform, value_transform) | |
| new_keys = keys.map(&key_transform) | |
| new_values = values.map(&value_transform) | |
| Hash[new_keys.zip(new_values)] | |
| end | |
| end | |
| hash = {"succeeded"=>"node2", "flagged"=>"node3"} | |
| transform = ->(v){v.to_sym} | |
| hash.mega_map(transform, transform) | |
| # => {:succeeded=>:node2, :flagged=>:node3} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So fancy! Very cool passage of the
transformlambda intomap.