I have an array of objects sorted by several properties of these objects. In priority order, these properties are foo , bar and baz . This means that objects are first sorted using foo ; then subsequences having the same foo value are sorted by bar ; and then those with the same foo and bar values ββsorted by baz .
I would like to turn this into a nested hash that reflects this grouping. I am mainly looking for recursive Enumerable#group_by . The keys are the values foo , bar and baz ; the values ββwill be either sub-hashes or arrays of objects. Here is an example:
[obj1, obj2, ... objn].group_by_recursive(:foo, :bar, :baz)
source share