Suppose I have:
a = Hash.new
a['google.com'][:traffic] << 50
a['google.com'][:traffic] << 20
a['google.com'][:popular] << 1
a['google.com'][:popular] << 2
3a['yahoo.com'][:anythinghere] << 3
needs to produce something like this:
a = { 'google.com' => {traffic: [50,20], popular: [1,2]}, 'yahoo.com' => { anythinghere: [3,4] } }
So far I've tried something of this kind in hope that it would produce this result:
a= Hash.new(Hash.new(Array.new))
For example, a['google.com']
would produce a new hash while a['google.com'][:anythinghere]
would produce a new array. When I try to execute the above insertions, however, a
is empty? No idea what's going on, I'm pretty sure I'm missing something fundamental here. Take a look:
a = stats = Hash.new(Hash.new(Array.new))
a['google.com'][:traffic] << 5
a['google.com'][:traffic] << 6
p a['google.com'][:traffic] #=> [5,6]
p a['google.com'] #=> empty hash???
p a #=> empty hash???