[DOC] Tweaks for Array#sort_by!

This commit is contained in:
BurdetteLamar 2024-10-17 16:51:26 -05:00 committed by Peter Zhu
parent eb8cf1d60e
commit 161ea389af
Notes: git 2024-10-18 15:09:01 +00:00

20
array.c
View File

@ -3556,28 +3556,24 @@ sort_by_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, dummy))
/* /*
* call-seq: * call-seq:
* array.sort_by! {|element| ... } -> self * sort_by! {|element| ... } -> self
* array.sort_by! -> new_enumerator * sort_by! -> new_enumerator
* *
* Sorts the elements of +self+ in place, * With a block given, sorts the elements of +self+ in place;
* using an ordering determined by the block; returns self. * returns self.
* *
* Calls the block with each successive element; * Calls the block with each successive element;
* sorts elements based on the values returned from the block. * sorts elements based on the values returned from the block:
*
* For duplicates returned by the block, the ordering is indeterminate, and may be unstable.
*
* This example sorts strings based on their sizes:
* *
* a = ['aaaa', 'bbb', 'cc', 'd'] * a = ['aaaa', 'bbb', 'cc', 'd']
* a.sort_by! {|element| element.size } * a.sort_by! {|element| element.size }
* a # => ["d", "cc", "bbb", "aaaa"] * a # => ["d", "cc", "bbb", "aaaa"]
* *
* Returns a new Enumerator if no block given: * For duplicate values returned by the block, the ordering is indeterminate, and may be unstable.
* *
* a = ['aaaa', 'bbb', 'cc', 'd'] * With no block given, returns a new Enumerator.
* a.sort_by! # => #<Enumerator: ["aaaa", "bbb", "cc", "d"]:sort_by!>
* *
* Related: see {Methods for Assigning}[rdoc-ref:Array@Methods+for+Assigning].
*/ */
static VALUE static VALUE