[前][次][番号順一覧][スレッド一覧]

ruby-changes:9070

From: knu <ko1@a...>
Date: Wed, 10 Dec 2008 12:59:08 +0900 (JST)
Subject: [ruby-changes:9070] Ruby:r20607 (trunk): * enumerator.c (enumerator_rewind): If the enclosed object

knu	2008-12-10 12:58:56 +0900 (Wed, 10 Dec 2008)

  New Revision: 20607

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20607

  Log:
    * enumerator.c (enumerator_rewind): If the enclosed object
      responds to a "rewind" method, call it; cf. [ruby-dev:37268]

  Modified files:
    trunk/ChangeLog
    trunk/enumerator.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 20606)
+++ ChangeLog	(revision 20607)
@@ -1,3 +1,8 @@
+Wed Dec 10 12:56:32 2008  Akinori MUSHA  <knu@i...>
+
+	* enumerator.c (enumerator_rewind): If the enclosed object
+	  responds to a "rewind" method, call it; cf. [ruby-dev:37268]
+
 Wed Dec 10 12:46:52 2008  Akinori MUSHA  <knu@i...>
 
 	* enumerator.c (enumerator_next): Fix a typo: s/rewinded/rewound/.
Index: enumerator.c
===================================================================
--- enumerator.c	(revision 20606)
+++ enumerator.c	(revision 20607)
@@ -22,6 +22,7 @@
  */
 VALUE rb_cEnumerator;
 static VALUE sym_each;
+static ID id_rewind;
 
 VALUE rb_eStopIteration;
 
@@ -532,6 +533,8 @@
  *   e.rewind   => e
  *
  * Rewinds the enumeration sequence by the next method.
+ *
+ * If the enclosed object responds to a "rewind" method, it is called.
  */
 
 static VALUE
@@ -539,6 +542,9 @@
 {
     struct enumerator *e = enumerator_ptr(obj);
 
+    if (rb_respond_to(e->obj, id_rewind))
+	rb_funcall(e->obj, id_rewind, 0);
+
     e->fib = 0;
     e->dst = Qnil;
     e->no_next = Qfalse;
@@ -861,6 +867,7 @@
     rb_define_method(rb_cYielder, "<<", yielder_yield, -2);
 
     sym_each = ID2SYM(rb_intern("each"));
+    id_rewind = rb_intern("rewind");
 
     rb_provide("enumerator.so");	/* for backward compatibility */
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]