list-bounce / example.com wrote:
> I try to get a hash of hash to make some sort of counter (I have a set
> of random pair and want to count the number of times they
> appear). I use
> this code but even if I can access data, my hash seems empty (so each
> and the others don't work):
>
>
> h =3D Hash.new(Hash.new(0))
> h["a"]["b"] +=3D 1
> h["a"]["b"] +=3D 1
> h["a"]["c"] +=3D 1
> p h["a"]["b"]  =3D> 2
> p h["a"]["c"]  =3D> 1
> p h.class  =3D> Hash
> p h["a"].class  =3D> Hash
> p h["a"]["b"].class  =3D> Fixnum
> p h  =3D> {}
>
>
> What's wrong?
>
> Lars

Try this definition:

h =3D Hash.new { |h, k|
  h[k] =3D Hash.new(0)
}

It will actually modify 'h' rather than simply returning and modifying the =
default value.

Gennady.