Skip to content

Instantly share code, notes, and snippets.

@mark
Created July 26, 2011 17:47
Show Gist options
  • Save mark/1107342 to your computer and use it in GitHub Desktop.
Save mark/1107342 to your computer and use it in GitHub Desktop.
New array methods
class Array
def hashify
Hash.new.tap do |hash|
each { |obj| hash[obj] = yield(obj) }
end
end
def reverse_hashify
Hash.new.tap do |hash|
each { |obj| hash[ yield(obj) ] = obj }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment