Merge and group multiple hashes by key


#1

Hello,

i have a problem i my program that i can’t solve. i’m recieving multiple
hashes and i what to merge them into only one hash and group them by
string, something like this:

{“Leadership”=>[3,2,5], “Motivation”=>[2,5], “Innovation”=> [2,4,4,2]}

the code that i have now is this:

...some code...

self_cc = {}

slf_cc.each do |cc|
  self_cc[cc.title] = cc.rate
end

#n1

n1_cc = {}

...some code...

n1_ccs.each do |cc|
  n1_cc[cc.title] = cc.rate
end

...some code...
team_array = []
...some code...

team_array.each do |team|

  team_user_ccs = mutual.where(team_id: team)

  team_user_ccs.each do |tucc|
    team_cc[tucc.title] = tucc.rate
  end
    #{"Leadership"=>2, "Innovation"=>3, "Motivation"=>5}
end
#new team with new "tucc"


rates = {}

keys = self_cc.keys
keys.each do |k|
  rates[k] = [self_cc[k], n1_cc[k]]
end

for now i could only add to my hash the self_cc and the n1_cc and group
them, i wanted to add the team_cc but the “team_array.each do |team|”
part makes difficult because in the team_cc i can recieve more than one
hash of keys and values. The keys are the same so i wanted to group all
the values i received.

Can anyone help me please?

Thank you