* array.c (rb_ary_sort_by_bang): new method. requested in

[ruby-core:21709]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21967 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2009-02-02 10:43:27 +00:00
Родитель 1d07fd73d8
Коммит 765a6be700
2 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -39,6 +39,11 @@ Mon Feb 2 14:53:35 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/socket.c (sock_initialize): make 3rd argument, protocol,
optional.
Mon Feb 2 14:47:53 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_sort_by_bang): new method. requested in
[ruby-core:21709]
Mon Feb 2 14:22:56 2009 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/socket/constants.c (cmsg_type_arg): INET6 check.

28
array.c
Просмотреть файл

@ -1843,6 +1843,33 @@ rb_ary_sort(VALUE ary)
}
static VALUE
sort_by_i(VALUE i)
{
return rb_yield(i);
}
/*
* call-seq:
* enum.sort_by! {| obj | block } -> array
*
* Sorts <i>enum</i> in place using a set of keys generated by mapping the
* values in <i>enum</i> through the given block.
*/
static VALUE
rb_ary_sort_by_bang(VALUE ary)
{
VALUE sorted;
RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_modify(ary);
sorted = rb_block_call(ary, rb_intern("sort_by"), 0, 0, sort_by_i, 0);
rb_ary_replace(ary, sorted);
return ary;
}
/*
* call-seq:
* array.collect {|item| block } -> an_array
@ -3830,6 +3857,7 @@ Init_Array(void)
rb_define_method(rb_cArray, "reverse!", rb_ary_reverse_bang, 0);
rb_define_method(rb_cArray, "sort", rb_ary_sort, 0);
rb_define_method(rb_cArray, "sort!", rb_ary_sort_bang, 0);
rb_define_method(rb_cArray, "sort_by!", rb_ary_sort_by_bang, 0);
rb_define_method(rb_cArray, "collect", rb_ary_collect, 0);
rb_define_method(rb_cArray, "collect!", rb_ary_collect_bang, 0);
rb_define_method(rb_cArray, "map", rb_ary_collect, 0);