D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Enumerable
/
Filename :
max-i.ri
back
Copy
U:RDoc::AnyMethod[iI"max:ETI"Enumerable#max;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"RReturns the element with the maximum element according to a given criterion. ;TI"IThe ordering of equal elements is indeterminate and may be unstable.;To:RDoc::Markup::BlankLine o; ; [I"AWith no argument and no block, returns the maximum element, ;TI"Ausing the elements' own method <tt>#<=></tt> for comparison:;T@o:RDoc::Markup::Verbatim; [ I")(1..4).max # => 4 ;TI"*(-4..-1).max # => -1 ;TI"+%w[d c b a].max # => "d" ;TI"1{foo: 0, bar: 1, baz: 2}.max # => [:foo, 0] ;TI"+[].max # => nil ;T:@format0o; ; [I"=With positive integer argument +n+ given, and no block, ;TI"Kreturns an array containing the first +n+ maximum elements that exist:;T@o;; [ I"1(1..4).max(2) # => [4, 3] ;TI"2(-4..-1).max(2) # => [-1, -2] ;TI"5%w[d c b a].max(2) # => ["d", "c"] ;TI"A{foo: 0, bar: 1, baz: 2}.max(2) # => [[:foo, 0], [:baz, 2]] ;TI"-[].max(2) # => [] ;T; 0o; ; [I"DWith a block given, the block determines the maximum elements. ;TI"HThe block is called with two elements +a+ and +b+, and must return:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"*A negative integer if <tt>a < b</tt>.;To;;0; [o; ; [I"Zero if <tt>a == b</tt>.;To;;0; [o; ; [I"*A positive integer if <tt>a > b</tt>.;T@o; ; [I")With a block given and no argument, ;TI"<returns the maximum element as determined by the block:;T@o;; [ I"C%w[xxx x xxxx xx].max {|a, b| a.size <=> b.size } # => "xxxx" ;TI""h = {foo: 0, bar: 1, baz: 2} ;TI"Fh.max {|pair1, pair2| pair1[1] <=> pair2[1] } # => [:baz, 2] ;TI"@[].max {|a, b| a <=> b } # => nil ;T; 0o; ; [I"AWith a block given and positive integer argument +n+ given, ;TI"Lreturns an array containing the first +n+ maximum elements that exist, ;TI" as determined by the block.;T@o;; [ I"O%w[xxx x xxxx xx].max(2) {|a, b| a.size <=> b.size } # => ["xxxx", "xxx"] ;TI""h = {foo: 0, bar: 1, baz: 2} ;TI"6h.max(2) {|pair1, pair2| pair1[1] <=> pair2[1] } ;TI"!# => [[:baz, 2], [:bar, 1]] ;TI"B[].max(2) {|a, b| a <=> b } # => [] ;T; 0o; ; [I"%Related: #min, #minmax, #max_by.;T: @fileI"enum.c;T:0@omit_headings_from_table_of_contents_below0I"|max -> element max(n) -> array max {|a, b| ... } -> element max(n) {|a, b| ... } -> array ;T0[ I"(*args);T@TFI"Enumerable;TcRDoc::NormalModule00