L
Lars Ticot
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 = Hash.new(Hash.new(0))
h["a"]["b"] += 1
h["a"]["b"] += 1
h["a"]["c"] += 1
p h["a"]["b"] => 2
p h["a"]["c"] => 1
p h.class => Hash
p h["a"].class => Hash
p h["a"]["b"].class => Fixnum
p h => {}
What's wrong?
Lars
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 = Hash.new(Hash.new(0))
h["a"]["b"] += 1
h["a"]["b"] += 1
h["a"]["c"] += 1
p h["a"]["b"] => 2
p h["a"]["c"] => 1
p h.class => Hash
p h["a"].class => Hash
p h["a"]["b"].class => Fixnum
p h => {}
What's wrong?
Lars