Skip to content

Commit b1ffd9e

Browse files
[DOC] Tweaks for Array#sort (#11907)
1 parent 0b38e18 commit b1ffd9e

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

array.c

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,44 +3455,33 @@ rb_ary_sort_bang(VALUE ary)
34553455

34563456
/*
34573457
* call-seq:
3458-
* array.sort -> new_array
3459-
* array.sort {|a, b| ... } -> new_array
3458+
* sort -> new_array
3459+
* sort {|a, b| ... } -> new_array
34603460
*
3461-
* Returns a new +Array+ whose elements are those from +self+, sorted.
3461+
* Returns a new array containing the elements of +self+, sorted.
34623462
*
3463-
* With no block, compares elements using operator <tt>#<=></tt>
3464-
* (see Comparable):
3463+
* With no block given, compares elements using operator <tt>#<=></tt>
3464+
* (see Object#<=>):
34653465
*
3466-
* a = 'abcde'.split('').shuffle
3467-
* a # => ["e", "b", "d", "a", "c"]
3468-
* a1 = a.sort
3469-
* a1 # => ["a", "b", "c", "d", "e"]
3466+
* [0, 2, 3, 1].sort # => [0, 1, 2, 3]
34703467
*
3471-
* With a block, calls the block with each element pair;
3472-
* for each element pair +a+ and +b+, the block should return an integer:
3468+
* With a block given, calls the block with each combination of pairs of elements from +self+;
3469+
* for each pair +a+ and +b+, the block should return a numeric:
34733470
*
34743471
* - Negative when +b+ is to follow +a+.
34753472
* - Zero when +a+ and +b+ are equivalent.
34763473
* - Positive when +a+ is to follow +b+.
34773474
*
34783475
* Example:
34793476
*
3480-
* a = 'abcde'.split('').shuffle
3481-
* a # => ["e", "b", "d", "a", "c"]
3482-
* a1 = a.sort {|a, b| a <=> b }
3483-
* a1 # => ["a", "b", "c", "d", "e"]
3484-
* a2 = a.sort {|a, b| b <=> a }
3485-
* a2 # => ["e", "d", "c", "b", "a"]
3477+
* a = [3, 2, 0, 1]
3478+
* a.sort {|a, b| a <=> b } # => [0, 1, 2, 3]
3479+
* a.sort {|a, b| b <=> a } # => [3, 2, 1, 0]
34863480
*
34873481
* When the block returns zero, the order for +a+ and +b+ is indeterminate,
3488-
* and may be unstable:
3489-
*
3490-
* a = 'abcde'.split('').shuffle
3491-
* a # => ["e", "b", "d", "a", "c"]
3492-
* a1 = a.sort {|a, b| 0 }
3493-
* a1 # => ["c", "e", "b", "d", "a"]
3482+
* and may be unstable.
34943483
*
3495-
* Related: Enumerable#sort_by.
3484+
* Related: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].
34963485
*/
34973486

34983487
VALUE

0 commit comments

Comments
 (0)