From: Robert Klemme Date: 2011-04-20T17:50:55+09:00 Subject: Re: Can I check contain value in hash? On Wed, Apr 20, 2011 at 10:33 AM, Brian Candler wrote: > For some applications, > >  dict[key] << val >  dict[key].uniq! > > will be good enough. But this will still slow down if the number of > values in the list gets large, in which case a hash of hashes would be > better: > >  dict[key] ||= {} >  dict[key][val] = true > > To get the values, you'd then use dict[key].keys (which in ruby 1.8 > would be in an arbitrary order, and in 1.9 would be in order of first > insertion) My first choice would be to use Set and not Hash as values. require 'set' dict = Hash.new {|h,k| h[k] = Set.new} dict[key] << val dict[key].include? val Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/