method

in_order_of

Importance_1
v7.1.3.2 - Show latest stable - 0 notes - Class: Enumerable
in_order_of(key, series) public

Returns a new Array where the order has been set to that provided in the series, based on the key of the objects in the original enumerable.

[ Person.find(5), Person.find(3), Person.find(1) ].in_order_of(:id, [ 1, 5, 3 ])
# => [ Person.find(1), Person.find(5), Person.find(3) ]

If the series include keys that have no corresponding element in the Enumerable, these are ignored. If the Enumerable has additional elements that aren’t named in the series, these are not included in the result.

Show source
Register or log in to add new notes.