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.sort {|x,y| y <=> x }
Show source
/*
* call-seq:
* array.sort! -> array
* array.sort! {| a,b | block } -> array
*
* Sorts _self_. Comparisons for
* the sort will be done using the <code><=></code> operator or using
* an optional code block. The block implements a comparison between
* <i>a</i> and <i>b</i>, returning -1, 0, or +1. See also
* <code>Enumerable
*
* a = [ "d", "a", "e", "c", "b" ]
* a.sort
* a.sort {|x,y| y <=> x }
*/
VALUE
rb_ary_sort_bang(ary)
VALUE ary;
{
rb_ary_modify(ary);
if (RARRAY(ary)->len > 1) {
FL_SET(ary, ARY_TMPLOCK); /* prohibit modification during sort */
rb_ensure(sort_internal, ary, sort_unlock, ary);
}
return ary;
}