Return to Snippet

Revision: 5804
at April 5, 2008 13:34 by jarnaldich


Initial Code
# a is the array we want to turn into a hash
Hash[*a.zip([true] * a.size).flatten]

# Example:
people= %w[John Mary Paul]
query_people=Hash[*people.zip([true] * people.size).flatten]

query_people["John"] # returns true
query_people["Wenceslas"] # returns nil (equivalent to false in most tests)

Initial URL


Initial Description
Useful for speeding up searches.

Initial Title
Turning array values into hash keys

Initial Tags
array

Initial Language
Ruby