sort()
public
Returns a new array created by sorting
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 -> an_array
* array.sort {| a,b | block } -> an_array
*
* Returns a new array created by sorting <i>self</i>. 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#sort_by</code>.
*
* a = [ "d", "a", "e", "c", "b" ]
* a.sort
* a.sort {|x,y| y <=> x }
*/
VALUE
rb_ary_sort(ary)
VALUE ary;
{
ary = rb_ary_dup(ary);
rb_ary_sort_bang(ary);
return ary;
}