/ Published in: Ruby

Useful for speeding up searches.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# 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)
Comments
