From: Jeremy Kemper Date: 2005-04-28T11:45:10+09:00 Subject: Re: Hash as Checklist basi wrote: > I need to check if a word is in a list. I'm using hash because the > lists can be long (i'm under the impression hash is faster than array). > Basically I'm only interested that a key exists. I have to create > entries like: > > h = { > "one" => true, > "two" => true, > "three" => true, > "four" => true, > "five" => true > } > > So h["one"] gives true, and h["seven"] returns nil. But typing the > dummy value "true" is a waste of effort, and there's an ugliness in > there. Is there a better way to design a simple checklist? Use a set: require 'set' words = %w(one two three four five).to_set words.include? 'one' # => true words.include? 'seven' # => false http://www.ruby-doc.org/stdlib/libdoc/set/rdoc/ jeremy