diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-03-17 09:07:18 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-03-17 09:07:18 +0000 |
commit | 6712cca3b5f040d0a4da03d660f3c1063ad5693c (patch) | |
tree | 319699b69e3688d9b1549d99965bc19607714d75 | |
parent | 929a85f60ec3f8a37ba78f0ceb69ecae75160eb5 (diff) |
* enumerator.c (Enumerator#{each_,}{with_index,with_object}): Fix
a bug where any parameter but the first one is dropped even if
multiple values are yielded with. [Bug #1198]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | enumerator.c | 19 |
2 files changed, 20 insertions, 5 deletions
@@ -1,3 +1,9 @@ +Tue Mar 17 18:00:55 2009 Akinori MUSHA <knu@iDaemons.org> + + * enumerator.c (Enumerator#{each_,}{with_index,with_object}): Fix + a bug where any parameter but the first one is dropped even if + multiple values are yielded with. [Bug #1198] + Tue Mar 17 14:25:16 2009 Tanaka Akira <akr@fsij.org> * lib/pathname.rb (Pathname#sub): set $~ in block.binding. diff --git a/enumerator.c b/enumerator.c index f55c3d8f6e..76696e0a66 100644 --- a/enumerator.c +++ b/enumerator.c @@ -397,11 +397,17 @@ enumerator_each(VALUE obj) } static VALUE -enumerator_with_index_i(VALUE val, VALUE *memo) +enumerator_with_index_i(VALUE val, VALUE *memo, int argc, VALUE *argv) { - val = rb_yield_values(2, val, INT2FIX(*memo)); + VALUE idx; + + idx = INT2FIX(*memo); ++*memo; - return val; + + if (argc <= 1) + return rb_yield_values(2, val, idx); + + return rb_yield_values(2, rb_ary_new4(argc, argv), idx); } /* @@ -451,9 +457,12 @@ enumerator_each_with_index(VALUE obj) } static VALUE -enumerator_with_object_i(VALUE val, VALUE memo) +enumerator_with_object_i(VALUE val, VALUE memo, int argc, VALUE *argv) { - return rb_yield_values(2, val, memo); + if (argc <= 1) + return rb_yield_values(2, val, memo); + + return rb_yield_values(2, rb_ary_new4(argc, argv), memo); } /* |