Let’s say we have a model called
Product with an attribute
Now we need to get the
minimum value of
price for an array of
We would get the minimum and maximum value using:
In the case of an ActiveRecord Collection, we could achieve this just by using
minimum directly on the collection as these methods are defined
Rails 7 added
minimum methods in the
Hence they can be used directly on all enumerable.
So from the above example,
This is a simple enhancement, but it helps a lot when we have to deal with enumerable directly and not ActiveRecord Collection objects.