ruby-changes:5144
From: knu <ko1@a...>
Date: Tue, 27 May 2008 19:26:02 +0900 (JST)
Subject: [ruby-changes:5144] Ruby:r16639 (ruby_1_8): * enum.c (enum_to_a): Pass arguments through to #each().
knu 2008-05-27 19:25:49 +0900 (Tue, 27 May 2008)
New Revision: 16639
Modified files:
branches/ruby_1_8/ChangeLog
branches/ruby_1_8/enum.c
Log:
* 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().
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/enum.c?r1=16639&r2=16638&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16639&r2=16638&diff_format=u
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog (revision 16638)
+++ ruby_1_8/ChangeLog (revision 16639)
@@ -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/enum.c
===================================================================
--- ruby_1_8/enum.c (revision 16638)
+++ ruby_1_8/enum.c (revision 16639)
@@ -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,8 +1821,8 @@
{
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);
@@ -1828,6 +1855,7 @@
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/