method

min

Importance_2
Ruby latest stable (v2_5_5) - 0 notes - Class: Array
min(p1 = v1) public

Returns the object in ary with the minimum value. The first form assumes all objects implement Comparable; the second uses the block to return a <=> b.

ary = %w(albatross dog horse)
ary.min                                   #=> "albatross"
ary.min { |a, b| a.length <=> b.length }  #=> "dog"

If the n argument is given, minimum n elements are returned as an array.

ary = %w[albatross dog horse]
ary.min(2)                                  #=> ["albatross", "dog"]
ary.min(2) {|a, b| a.length <=> b.length }  #=> ["dog", "horse"]
Show source
Register or log in to add new notes.