method
min_by
![Some documentation Importance_1](https://d2vfyqvduarcvs.cloudfront.net/images/importance_1.png?1349367920)
Ruby latest stable (v2_5_5)
-
0 notes -
Class: Enumerable
min_by(p1 = v1)
public
Returns the object in enum that gives the minimum value from the given block.
If no block is given, an enumerator is returned instead.
a = %w(albatross dog horse) a.min_by { |x| x.length } #=> "dog"
If the n argument is given, minimum n elements are returned as an array. These n elements are sorted by the value from the given block.
a = %w[albatross dog horse] p a.min_by(2) {|x| x.length } #=> ["dog", "horse"]