method
max
v2_6_3 -
Show latest stable
- Class:
Array
max(*args)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"]