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 | 85f34433c4918a763813a14568ea2ea1bfbd6b6a (patch) | |
| tree | 319699b69e3688d9b1549d99965bc19607714d75 /enumerator.c | |
| parent | b7f376baa1d3e92e0e71258607ae3f2216101a04 (diff) | |
| download | ruby-85f34433c4918a763813a14568ea2ea1bfbd6b6a.tar.gz ruby-85f34433c4918a763813a14568ea2ea1bfbd6b6a.tar.xz ruby-85f34433c4918a763813a14568ea2ea1bfbd6b6a.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@22992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enumerator.c')
| -rw-r--r-- | enumerator.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/enumerator.c b/enumerator.c index f55c3d8f6..76696e0a6 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); } /* |
