ruby-changes:15179
From: knu <ko1@a...>
Date: Fri, 26 Mar 2010 12:47:38 +0900 (JST)
Subject: [ruby-changes:15179] Ruby:r27059 (ruby_1_8): * enum.c (Enumerable#each_entry): New method.
knu 2010-03-26 12:45:32 +0900 (Fri, 26 Mar 2010) New Revision: 27059 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27059 Log: * enum.c (Enumerable#each_entry): New method. Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/NEWS branches/ruby_1_8/enum.c Index: ruby_1_8/NEWS =================================================================== --- ruby_1_8/NEWS (revision 27058) +++ ruby_1_8/NEWS (revision 27059) @@ -56,6 +56,10 @@ New method with which replaces #choice. + * Enumerator#each_entry + + New method. + * Enumerable#each_with_object * Enumerator#with_object Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 27058) +++ ruby_1_8/ChangeLog (revision 27059) @@ -1,3 +1,7 @@ +Fri Mar 26 12:44:08 2010 Akinori MUSHA <knu@i...> + + * enum.c (Enumerable#each_entry): New method. + Fri Mar 26 04:52:19 2010 Hidetoshi NAGAI <nagai@a...> * ext/tk/extconf.rb: fix [ruby-core:28901] [Bug #2997]. Index: ruby_1_8/enum.c =================================================================== --- ruby_1_8/enum.c (revision 27058) +++ ruby_1_8/enum.c (revision 27059) @@ -1541,6 +1541,48 @@ static VALUE +each_val_i(i, p) + VALUE i, p; +{ + rb_yield(i); + return Qnil; +} + +/* + * call-seq: + * enum.each_entry {|obj| block} => enum + * + * Calls <i>block</i> once for each element in <i>self</i>, passing that + * element as a parameter, converting multiple values from yield to an + * array. + * + * class Foo + * include Enumerable + * def each + * yield 1 + * yield 1,2 + * end + * end + * Foo.new.each_entry{|o| print o, " -- "} + * + * produces: + * + * 1 -- [1, 2] -- + */ + +static VALUE +enum_each_entry(argc, argv, obj) + int argc; + VALUE *argv; + VALUE obj; +{ + RETURN_ENUMERATOR(obj, argc, argv); + rb_block_call(obj, id_each, argc, argv, each_val_i, 0); + return obj; +} + + +static VALUE zip_i(val, memo) VALUE val; VALUE *memo; @@ -1883,6 +1925,7 @@ 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, "each_entry", enum_each_entry, -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/