[DOC] Tweaks for Array#max (#11768)
This commit is contained in:
parent
2f5ab4c4b8
commit
253b76ec0a
Notes:
git
2024-10-02 17:54:30 +00:00
Merged-By: peterzhu2118 <peter@peterzhu.ca>
47
array.c
47
array.c
@ -5916,42 +5916,51 @@ ary_max_opt_string(VALUE ary, long i, VALUE vmax)
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* array.max -> element
|
||||
* array.max {|a, b| ... } -> element
|
||||
* array.max(n) -> new_array
|
||||
* array.max(n) {|a, b| ... } -> new_array
|
||||
* max -> element
|
||||
* max(n) -> new_array
|
||||
* max {|a, b| ... } -> element
|
||||
* max(n) {|a, b| ... } -> new_array
|
||||
*
|
||||
* Returns one of the following:
|
||||
*
|
||||
* - The maximum-valued element from +self+.
|
||||
* - A new +Array+ of maximum-valued elements selected from +self+.
|
||||
* - A new array of maximum-valued elements from +self+.
|
||||
*
|
||||
* When no block is given, each element in +self+ must respond to method <tt><=></tt>
|
||||
* with an Integer.
|
||||
* Does not modify +self+.
|
||||
*
|
||||
* With no block given, each element in +self+ must respond to method <tt>#<=></tt>
|
||||
* with a numeric.
|
||||
*
|
||||
* With no argument and no block, returns the element in +self+
|
||||
* having the maximum value per method <tt><=></tt>:
|
||||
*
|
||||
* [0, 1, 2].max # => 2
|
||||
* [1, 0, 3, 2].max # => 3
|
||||
*
|
||||
* With an argument Integer +n+ and no block, returns a new +Array+ with at most +n+ elements,
|
||||
* in descending order per method <tt><=></tt>:
|
||||
* With non-negative numeric argument +n+ and no block,
|
||||
* returns a new array with at most +n+ elements,
|
||||
* in descending order, per method <tt><=></tt>:
|
||||
*
|
||||
* [0, 1, 2, 3].max(3) # => [3, 2, 1]
|
||||
* [0, 1, 2, 3].max(6) # => [3, 2, 1, 0]
|
||||
* [1, 0, 3, 2].max(3) # => [3, 2, 1]
|
||||
* [1, 0, 3, 2].max(3.0) # => [3, 2, 1]
|
||||
* [1, 0, 3, 2].max(9) # => [3, 2, 1, 0]
|
||||
* [1, 0, 3, 2].max(0) # => []
|
||||
*
|
||||
* When a block is given, the block must return an Integer.
|
||||
* With a block given, the block must return a numeric.
|
||||
*
|
||||
* With a block and no argument, calls the block <tt>self.size-1</tt> times to compare elements;
|
||||
* returns the element having the maximum value per the block:
|
||||
* With a block and no argument, calls the block <tt>self.size - 1</tt> times to compare elements;
|
||||
* returns the element having the maximum return value from the block:
|
||||
*
|
||||
* ['0', '00', '000'].max {|a, b| a.size <=> b.size } # => "000"
|
||||
* ['0', '', '000', '00'].max {|a, b| a.size <=> b.size }
|
||||
* # => "000"
|
||||
*
|
||||
* With an argument +n+ and a block, returns a new +Array+ with at most +n+ elements,
|
||||
* in descending order per the block:
|
||||
* With non-negative numeric argument +n+ and a block,
|
||||
* returns a new array with at most +n+ elements,
|
||||
* in descending order, per the block:
|
||||
*
|
||||
* ['0', '00', '000'].max(2) {|a, b| a.size <=> b.size } # => ["000", "00"]
|
||||
* ['0', '', '000', '00'].max(2) {|a, b| a.size <=> b.size }
|
||||
* # => ["000", "00"]
|
||||
*
|
||||
* Related: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].
|
||||
*/
|
||||
static VALUE
|
||||
rb_ary_max(int argc, VALUE *argv, VALUE ary)
|
||||
|
Loading…
x
Reference in New Issue
Block a user