I'm looking to change my array of hashes, to combine all hashes with same keys and different values into same hash, here is what I mean:
[
[0] {
"Property 1" => {
"Portal" => #<Client:0x70aa253d> {
:team_id => 1,
:cap_id => 25,
:user_id => 145,
:active => true,
:created_at => Wed, 18 Mar 2015 11:52:11 EDT -04:00,
:updated_at => Wed, 18 Mar 2015 11:52:11 EDT -04:00
}
}
},
[1] {
"Property 2" => {
"Client Solutions" => #<Client:0x70aa221c> {
:team_id => 2,
:cap_id => 25,
:user_id => 145,
:active => true,
:created_at => Wed, 18 Mar 2015 11:52:27 EDT -04:00,
:updated_at => Fri, 20 Mar 2015 12:32:52 EDT -04:00
}
}
},
[2] {
"Property 1" => {
"Other" => #<Client:0x680f8067> {
:team_id => 2,
:cap_id => 25,
:user_id => 145,
:active => true,
:created_at => Fri, 20 Mar 2015 12:52:23 EDT -04:00,
:updated_at => Fri, 20 Mar 2015 12:52:23 EDT -04:00
}
}
}
]
So after the merge the array of hashes should look like this :
[
[0] {
"Property 1" => {
"Portal" => #<Client:0x70aa253d> {
:team_id => 1,
:cap_id => 25,
:user_id => 145,
:active => true,
:created_at => Wed, 18 Mar 2015 11:52:11 EDT -04:00,
:updated_at => Wed, 18 Mar 2015 11:52:11 EDT -04:00
},
"Other" => #<Client:0x680f8067> {
:team_id => 2,
:cap_id => 25,
:user_id => 145,
:active => true,
:created_at => Fri, 20 Mar 2015 12:52:23 EDT -04:00,
:updated_at => Fri, 20 Mar 2015 12:52:23 EDT -04:00
}
}
},
[1] {
"Property 2" => {
"Client Solutions" => #<Client:0x70aa221c> {
:team_id => 2,
:cap_id => 25,
:user_id => 145,
:active => true,
:created_at => Wed, 18 Mar 2015 11:52:27 EDT -04:00,
:updated_at => Fri, 20 Mar 2015 12:32:52 EDT -04:00
}
}
}
]
I tried couple of things, looks like merge and reverse_merge are ignoring the duplicate values. Assuming result is the variable holding the array of hashes, tried this :
result.inject(:merge)
result.reduce(&:merge)
result.reduce({}, :reverse_merge)
Depending on which merge do I use reverse_merge or merge I get only 1 of the values that should be in property 1.
I get either Portal or Other in the Property, can't get both of them like described, what am I doing wrong?