[DOC] Tweaks for Array#minmax (#11787)

This commit is contained in:
Burdette Lamar 2024-10-04 12:34:11 -05:00 committed by GitHub
parent 5a95a69058
commit 95ad0e5f85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2024-10-04 17:34:30 +00:00
Merged-By: peterzhu2118 <peter@peterzhu.ca>

27
array.c
View File

@ -6181,26 +6181,25 @@ rb_ary_min(int argc, VALUE *argv, VALUE ary)
/*
* call-seq:
* array.minmax -> [min_val, max_val]
* array.minmax {|a, b| ... } -> [min_val, max_val]
* minmax -> array
* minmax {|a, b| ... } -> array
*
* Returns a new 2-element +Array+ containing the minimum and maximum values
* from +self+, either per method <tt>#<=></tt> or per a given block:.
* Returns a 2-element array containing the minimum-valued and maximum-valued
* elements from +self+;
* does not modify +self+.
*
* When no block is given, each element in +self+ must respond to method <tt>#<=></tt>
* with an Integer;
* returns a new 2-element +Array+ containing the minimum and maximum values
* from +self+, per method <tt>#<=></tt>:
* With no block given, the minimum and maximum values are determined using method <tt>#<=></tt>:
*
* [0, 1, 2].minmax # => [0, 2]
* [1, 0, 3, 2].minmax # => [0, 3]
*
* When a block is given, the block must return an Integer;
* the block is called <tt>self.size-1</tt> times to compare elements;
* returns a new 2-element +Array+ containing the minimum and maximum values
* from +self+, per the block:
* With a block given, the block must return a numeric;
* the block is called <tt>self.size - 1</tt> times to compare elements;
* returns the elements having the minimum and maximum values per the block:
*
* ['0', '00', '000'].minmax {|a, b| a.size <=> b.size } # => ["0", "000"]
* ['0', '', '000', '00'].minmax {|a, b| a.size <=> b.size }
* # => ["", "000"]
*
* Related: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].
*/
static VALUE
rb_ary_minmax(VALUE ary)