From: "Jesús Gabriel y Galán" Date: 2010-03-25T18:35:47+09:00 Subject: Re: hash problem On Thu, Mar 25, 2010 at 10:29 AM, Adam Nelreth wrote: > Ok - I know how to increase counter - bigger problem is with how to find > this ip in table > > This is how I try to do this: > > if test.has_key?(ip) == true >    print "ip in table" > else >    test[ip] = 1 > end > First of all, with the mechanism of the default value you don't need to check for the key to set the initial value. It's done for you, as I explained before: h = Hash.new(0) h[k] += 1 will set h[k] to 1 the first time, and increase it by one afterwards. On the other hand, this does work for me: irb(main):020:0> if h.has_key?("10.1.1.3") == true irb(main):021:1> puts "found" irb(main):022:1> end found Although for boolean comparison, the idiomatic way is to check against the expression itself, instead of comparing to true, since in Ruby anything that is not nil or false will be "truthy" in a boolean expression irb(main):017:0> if h.has_key?("10.1.1.3") irb(main):018:1> puts "found" irb(main):019:1> end found Jesus.