Skip to content

Instantly share code, notes, and snippets.

@stringsn88keys
Created September 12, 2013 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stringsn88keys/6540365 to your computer and use it in GitHub Desktop.
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]]
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