From: "Jesús Gabriel y Galán" Date: 2011-04-20T16:49:38+09:00 Subject: Re: Can I check contain value in hash? On Wed, Apr 20, 2011 at 6:02 AM, Siratinee Sukachai wrote: > I have hash which is contain list of string value. > I need to check is the value already contained in the key. > Add add the value to the key if the key is not contained that value. > Can I do that? > > like in c# > > if(!dict[key].contains(value)) > { >  dict[key].add(value); > } You can try the code. A similar approach to the c# above could use methods Hash#has_key? (http://ruby-doc.org/core-1.8.7/classes/Hash.html#M000515), Array#include (http://ruby-doc.org/core-1.8.7/classes/Array.html#M000343) and Array#<< (http://ruby-doc.org/core-1.8.7/classes/Array.html#M000306). Although if your arrays can grow and so you are checking include? many times on big arrays, you might want to use a Set instead of an Array. Jesus.