I've this hash
{
19132=>{
:occurences=>34,
:name=>"bar"
},
19133=>{
:occurences=>19,
:name=>"foo"
}
}
I would like to find the addition of occurrences (34+19) in a new key (why not total
) on each key (19132 and 19133).
I've something like:
my_hash = {19132=>{:occurences=>34, :name=>"bar"}, 19133=>{:occurences=>19, :name=>"foo"}}
my_hash.values.inject{|memo, el| memo.merge(el){|k, old_v, new_v| old_v + new_v if k.is_a?(Numeric)}}
I've found some help Here but I'm stuck with the merge. I don't even know if this method can solve my problem.