method
sort!
v1_8_7_330 -
Show latest stable
- Class:
Array
sort!()public
Sorts self. Comparisons for the sort will be done using the <=> operator or using an optional code block. The block implements a comparison between a and b, returning -1, 0, or +1. See also Enumerable#sort_by.
a = [ "d", "a", "e", "c", "b" ] a.sort #=> ["a", "b", "c", "d", "e"] a.sort {|x,y| y <=> x } #=> ["e", "d", "c", "b", "a"]
1Note
Sort Integers
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
==== Sort From Greatest to Smallest
>> [1, 2, 3, 4].sort { |a, z| z <=> a }
=> [4, 3, 2, 1]