From: Martin DeMello Date: 2009-02-04T23:27:12+09:00 Subject: Re: Hash counting On Wed, Feb 4, 2009 at 12:04 AM, Stuart Clarke wrote: > > counts = Hash.new(0) > eventdateID.each {|d| counts[d] += 1} Here is your problem. Hash.new(0) means "when I query the hash, and the key I request is not in there, return 0". It does not actually add {key => 0} to the hash itself. To do that, you need the block form of Hash.new, which yields as block the hash itself and the key: counts = Hash.new {|h, k| h[k] = 0} irb(main):001:0> a = Hash.new(0) => {} irb(main):002:0> b = Hash.new {|h,k| h[k] = 0} => {} irb(main):003:0> a['hello'] => 0 irb(main):004:0> b['hello'] => 0 irb(main):005:0> a => {} irb(main):006:0> b => {"hello"=>0} martin