Hash counting

Or square bracket method

Hash[1,2,3,4] # => {1 => 2, 3 => 4}

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

On 05/02/2009, at 1:27 AM, Martin DeMello [email protected]

On Wed, Feb 4, 2009 at 8:48 PM, Jesús Gabriel y
Galán[email protected] wrote:

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.

This is true, but counts[d] += 1 is actually counts[d] = counts[d] + 1
so the RHS will evaluate to 1 the first time, assigning it to the hash:

Oops - yes, missed that.

martin