instance method
in_order_of
Ruby on Rails 7.1.6
Since v7.0.10Signature
in_order_of(key, series)
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.
Parameters
-
keyreq -
seriesreq
Source
# File activesupport/lib/active_support/core_ext/enumerable.rb, line 196
def in_order_of(key, series)
group_by(&key).values_at(*series).flatten(1).compact
end
Defined in activesupport/lib/active_support/core_ext/enumerable.rb line 196
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Enumerable