mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Set the size of a new enumerator created by Enumerator#each with arguments to nil
When each() takes arguments, it is never safe to assume that the iteration would repeat the same number of times as with each() without any argument. Actually, there is no way to get the exact number, so the size should be set to nil to denote that. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d96483de72
commit
8717f0787d
2 changed files with 7 additions and 2 deletions
|
@ -550,6 +550,8 @@ enumerator_each(int argc, VALUE *argv, VALUE obj)
|
||||||
args = rb_ary_new4(argc, argv);
|
args = rb_ary_new4(argc, argv);
|
||||||
}
|
}
|
||||||
e->args = args;
|
e->args = args;
|
||||||
|
e->size = Qnil;
|
||||||
|
e->size_fn = 0;
|
||||||
}
|
}
|
||||||
if (!rb_block_given_p()) return obj;
|
if (!rb_block_given_p()) return obj;
|
||||||
return enumerator_block_call(obj, 0, obj);
|
return enumerator_block_call(obj, 0, obj);
|
||||||
|
|
|
@ -301,8 +301,11 @@ class TestEnumerator < Test::Unit::TestCase
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
ary = []
|
ary = []
|
||||||
e = o.to_enum.each(ary)
|
e = o.to_enum { 1 }
|
||||||
e.next
|
assert_equal(1, e.size)
|
||||||
|
e_arg = e.each(ary)
|
||||||
|
assert_equal(nil, e_arg.size)
|
||||||
|
e_arg.next
|
||||||
assert_equal([1], ary)
|
assert_equal([1], ary)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue