I would like to group an array of arrays of objects by object attribute.
So, if we have
array =[[object1, object2], [object3], [object4, object5, object6]]
and this object has an attribute say "source". Now assume each object has the following source value:
object1> source=source1
object2> source=source2
object3> source=source2
object4> source=source1
object5> source=source1
object6> source=source3
I want to group the arrays that are inside "array" by source attribute.
so I would like to have:
source1 => [object1, object2], [object4, object5, object6]
source2 => [object1, object2]
source3 => [object4, object5, object6]
for source2, I don't care about array of size 1 so I don't want to add [object3]
Any help?
array.flatten.group_by(&:source)? Be more concise please.