Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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