ruby-changes:5145
From: knu <ko1@a...>
Date: Tue, 27 May 2008 19:26:42 +0900 (JST)
Subject: [ruby-changes:5145] Ruby:r16640 (ruby_1_8_7): Merge from ruby_1_8.
knu 2008-05-27 19:26:30 +0900 (Tue, 27 May 2008) New Revision: 16640 Modified files: branches/ruby_1_8_7/ChangeLog branches/ruby_1_8_7/enum.c Log: Merge from ruby_1_8. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/enum.c?r1=16640&r2=16639&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/ChangeLog?r1=16640&r2=16639&diff_format=u Index: ruby_1_8_7/ChangeLog =================================================================== --- ruby_1_8_7/ChangeLog (revision 16639) +++ ruby_1_8_7/ChangeLog (revision 16640) @@ -1,3 +1,9 @@ +Tue May 27 19:24:40 2008 Akinori MUSHA <knu@i...> + + * enum.c (enum_to_a): Pass arguments through to #each(). + (enum_sort): Follow the enum_to_a signature change. + (enum_reverse_each): Add #reverse_each(). + Tue May 27 18:54:02 2008 Akinori MUSHA <knu@i...> * ext/stringio/stringio.c (strio_each_char, Init_stringio): Add Index: ruby_1_8_7/enum.c =================================================================== --- ruby_1_8_7/enum.c (revision 16639) +++ ruby_1_8_7/enum.c (revision 16640) @@ -426,12 +426,14 @@ * { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]] */ static VALUE -enum_to_a(obj) +enum_to_a(argc, argv, obj) + int argc; + VALUE *argv; VALUE obj; { VALUE ary = rb_ary_new(); - rb_iterate(rb_each, obj, collect_all, ary); + rb_block_call(obj, id_each, argc, argv, collect_all, ary); return ary; } @@ -709,7 +711,7 @@ enum_sort(obj) VALUE obj; { - return rb_ary_sort(enum_to_a(obj)); + return rb_ary_sort(enum_to_a(0, 0, obj)); } static VALUE @@ -1487,7 +1489,32 @@ return obj; } +/* + * call-seq: + * enum.reverse_each {|item| block } + * + * Traverses <i>enum</i> in reverse order. + */ + static VALUE +enum_reverse_each(int argc, VALUE *argv, VALUE obj) +{ + VALUE ary; + long i; + + RETURN_ENUMERATOR(obj, argc, argv); + + ary = enum_to_a(argc, argv, obj); + + for (i = RARRAY_LEN(ary); --i >= 0; ) { + rb_yield(RARRAY_PTR(ary)[i]); + } + + return obj; +} + + +static VALUE zip_i(val, memo) VALUE val; VALUE *memo; @@ -1794,40 +1821,41 @@ { rb_mEnumerable = rb_define_module("Enumerable"); - rb_define_method(rb_mEnumerable,"to_a", enum_to_a, 0); - rb_define_method(rb_mEnumerable,"entries", enum_to_a, 0); + rb_define_method(rb_mEnumerable, "to_a", enum_to_a, -1); + rb_define_method(rb_mEnumerable, "entries", enum_to_a, -1); - rb_define_method(rb_mEnumerable,"sort", enum_sort, 0); - rb_define_method(rb_mEnumerable,"sort_by", enum_sort_by, 0); - rb_define_method(rb_mEnumerable,"grep", enum_grep, 1); - rb_define_method(rb_mEnumerable,"count", enum_count, -1); - rb_define_method(rb_mEnumerable,"find", enum_find, -1); - rb_define_method(rb_mEnumerable,"detect", enum_find, -1); - rb_define_method(rb_mEnumerable,"find_index", enum_find_index, -1); - rb_define_method(rb_mEnumerable,"find_all", enum_find_all, 0); - rb_define_method(rb_mEnumerable,"select", enum_find_all, 0); - rb_define_method(rb_mEnumerable,"reject", enum_reject, 0); - rb_define_method(rb_mEnumerable,"collect", enum_collect, 0); - rb_define_method(rb_mEnumerable,"map", enum_collect, 0); - rb_define_method(rb_mEnumerable,"inject", enum_inject, -1); - rb_define_method(rb_mEnumerable,"reduce", enum_inject, -1); - rb_define_method(rb_mEnumerable,"partition", enum_partition, 0); - rb_define_method(rb_mEnumerable,"group_by", enum_group_by, 0); - rb_define_method(rb_mEnumerable,"first", enum_first, -1); - rb_define_method(rb_mEnumerable,"all?", enum_all, 0); - rb_define_method(rb_mEnumerable,"any?", enum_any, 0); - rb_define_method(rb_mEnumerable,"one?", enum_one, 0); - rb_define_method(rb_mEnumerable,"none?", enum_none, 0); - rb_define_method(rb_mEnumerable,"min", enum_min, 0); - rb_define_method(rb_mEnumerable,"max", enum_max, 0); - rb_define_method(rb_mEnumerable,"minmax", enum_minmax, 0); - rb_define_method(rb_mEnumerable,"min_by", enum_min_by, 0); - rb_define_method(rb_mEnumerable,"max_by", enum_max_by, 0); - rb_define_method(rb_mEnumerable,"minmax_by", enum_minmax_by, 0); - rb_define_method(rb_mEnumerable,"member?", enum_member, 1); - rb_define_method(rb_mEnumerable,"include?", enum_member, 1); - rb_define_method(rb_mEnumerable,"each_with_index", enum_each_with_index, 0); - rb_define_method(rb_mEnumerable,"enum_with_index", enum_each_with_index, 0); + rb_define_method(rb_mEnumerable, "sort", enum_sort, 0); + rb_define_method(rb_mEnumerable, "sort_by", enum_sort_by, 0); + rb_define_method(rb_mEnumerable, "grep", enum_grep, 1); + rb_define_method(rb_mEnumerable, "count", enum_count, -1); + rb_define_method(rb_mEnumerable, "find", enum_find, -1); + rb_define_method(rb_mEnumerable, "detect", enum_find, -1); + rb_define_method(rb_mEnumerable, "find_index", enum_find_index, -1); + rb_define_method(rb_mEnumerable, "find_all", enum_find_all, 0); + rb_define_method(rb_mEnumerable, "select", enum_find_all, 0); + rb_define_method(rb_mEnumerable, "reject", enum_reject, 0); + rb_define_method(rb_mEnumerable, "collect", enum_collect, 0); + rb_define_method(rb_mEnumerable, "map", enum_collect, 0); + rb_define_method(rb_mEnumerable, "inject", enum_inject, -1); + rb_define_method(rb_mEnumerable, "reduce", enum_inject, -1); + rb_define_method(rb_mEnumerable, "partition", enum_partition, 0); + rb_define_method(rb_mEnumerable, "group_by", enum_group_by, 0); + rb_define_method(rb_mEnumerable, "first", enum_first, -1); + rb_define_method(rb_mEnumerable, "all?", enum_all, 0); + rb_define_method(rb_mEnumerable, "any?", enum_any, 0); + rb_define_method(rb_mEnumerable, "one?", enum_one, 0); + rb_define_method(rb_mEnumerable, "none?", enum_none, 0); + rb_define_method(rb_mEnumerable, "min", enum_min, 0); + rb_define_method(rb_mEnumerable, "max", enum_max, 0); + rb_define_method(rb_mEnumerable, "minmax", enum_minmax, 0); + rb_define_method(rb_mEnumerable, "min_by", enum_min_by, 0); + rb_define_method(rb_mEnumerable, "max_by", enum_max_by, 0); + rb_define_method(rb_mEnumerable, "minmax_by", enum_minmax_by, 0); + rb_define_method(rb_mEnumerable, "member?", enum_member, 1); + rb_define_method(rb_mEnumerable, "include?", enum_member, 1); + rb_define_method(rb_mEnumerable, "each_with_index", enum_each_with_index, 0); + rb_define_method(rb_mEnumerable, "enum_with_index", enum_each_with_index, 0); + rb_define_method(rb_mEnumerable, "reverse_each", enum_reverse_each, -1); rb_define_method(rb_mEnumerable, "zip", enum_zip, -1); rb_define_method(rb_mEnumerable, "take", enum_take, 1); rb_define_method(rb_mEnumerable, "take_while", enum_take_while, 0); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/