Created
September 12, 2013 16:30
-
-
Save stringsn88keys/6540365 to your computer and use it in GitHub Desktop.
Patch to invert mappings of [key, value] in Hash to mappings of [value, [key1, key2, key3]]
This file contains 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 invert_as_arrays | |
self.inject({}) { |r,x| r[x[1]] ||= []; r[x[1]] << x[0]; r } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment