sort()
public
Returns an array containing the items in enum sorted, either
according to their own <=> method, or by using the results of the
supplied block. The block should return -1, 0, or +1 depending on the
comparison between a and b. As of Ruby 1.8, the method Enumerable#sort_by implements a
built-in Schwartzian Transform, useful when key computation or comparison
is expensive..
%w(rhea kea flea).sort
(1..10).sort {|a,b| b <=> a}
Show source
/*
* call-seq:
* enum.sort => array
* enum.sort {| a, b | block } => array
*
* Returns an array containing the items in <i>enum</i> sorted,
* either according to their own <code><=></code> method, or by using
* the results of the supplied block. The block should return -1, 0, or
* +1 depending on the comparison between <i>a</i> and <i>b</i>. As of
* Ruby 1.8, the method <code>Enumerable#sort_by</code> implements a
* built-in Schwartzian Transform, useful when key computation or
* comparison is expensive..
*
* %w(rhea kea flea).sort
* (1..10).sort {|a,b| b <=> a}
*/
static VALUE
enum_sort(obj)
VALUE obj;
{
return rb_ary_sort(enum_to_a(0, 0, obj));
}