Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!feeds.phibee-telecom.net!talisker.lacave.net!lacave.net!not-for-mail From: Brian Candler Newsgroups: comp.lang.ruby Subject: Re: Can I check contain value in hash? Date: Wed, 20 Apr 2011 03:33:47 -0500 Organization: Service de news de lacave.net Lines: 19 Message-ID: References: <4c6b84f27beab6e6f15f2d315a4bef87@ruby-forum.com> NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1303288692 56653 65.111.164.187 (20 Apr 2011 08:38:12 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Wed, 20 Apr 2011 08:38:12 +0000 (UTC) In-Reply-To: X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 381903 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:3222 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) -- Posted via http://www.ruby-forum.com/.