Flowdock
method

max

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

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

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

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

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