mirror of
https://github.com/ruby/ruby.git
synced 2026-11-08 01:20:26 +08:00
[Bug #22496] Make lazy each_with_index call super
`Lasy::Enumerator#each_with_index` should not be lazy when the block is given. Fix up for [Bug #21142].
This commit is contained in:
parent
64d821e685
commit
90dbced795
Notes:
git
2026-11-03 03:34:21 +00:00
@ -2770,6 +2770,9 @@ lazy_with_index_from(VALUE obj, VALUE memo)
|
||||
static VALUE
|
||||
lazy_each_with_index(VALUE obj)
|
||||
{
|
||||
if (rb_block_given_p()) {
|
||||
return rb_call_super(0, 0);
|
||||
}
|
||||
return lazy_with_index_from(obj, LONG2NUM(0));
|
||||
}
|
||||
|
||||
|
||||
@ -765,6 +765,10 @@ EOS
|
||||
|
||||
ary = 100.times.lazy.take(0).each_with_index.to_a
|
||||
assert_equal([], ary)
|
||||
|
||||
ary = []
|
||||
3.times.lazy.each_with_index { |*a| ary << a }
|
||||
assert_equal([[0, 0], [1, 1], [2, 2]], ary)
|
||||
end
|
||||
|
||||
def test_with_index_size
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user