diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-10 03:58:56 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-10 03:58:56 +0000 |
commit | 723f1729546d202bdec8b8118f6d18d291ed3295 (patch) | |
tree | 3339b93d2f72ddf43e12ada34b5b6f294a478e76 | |
parent | 3da081cdb9ef31dbddd623c486945e0e80c0b46f (diff) | |
download | ruby-723f1729546d202bdec8b8118f6d18d291ed3295.tar.gz ruby-723f1729546d202bdec8b8118f6d18d291ed3295.tar.xz ruby-723f1729546d202bdec8b8118f6d18d291ed3295.zip |
* enumerator.c (enumerator_rewind): If the enclosed object
responds to a "rewind" method, call it; cf. [ruby-dev:37268]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@20607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | enumerator.c | 7 |
2 files changed, 12 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Wed Dec 10 12:56:32 2008 Akinori MUSHA <knu@iDaemons.org> + + * 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@iDaemons.org> * enumerator.c (enumerator_next): Fix a typo: s/rewinded/rewound/. diff --git a/enumerator.c b/enumerator.c index f063dfb3d..e1cd1d65f 100644 --- a/enumerator.c +++ b/enumerator.c @@ -22,6 +22,7 @@ */ VALUE rb_cEnumerator; static VALUE sym_each; +static ID id_rewind; VALUE rb_eStopIteration; @@ -532,6 +533,8 @@ enumerator_next(VALUE obj) * 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 @@ enumerator_rewind(VALUE obj) { 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 @@ Init_Enumerator(void) 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 */ } |