module Enumerable
def in_order_of(key, series)
If the +series+ include keys that have no corresponding element in the Enumerable, these are ignored.
# => [ Person.find(1), Person.find(5), Person.find(3) ]
[ Person.find(5), Person.find(3), Person.find(1) ].in_order_of(:id, [ 1, 5, 3 ])
objects in the original enumerable.
Returns a new +Array+ where the order has been set to that provided in the +series+, based on the +key+ of the
def in_order_of(key, series) group_by(&key).values_at(*series).flatten(1).compact end