зеркало из https://github.com/github/ruby.git
* enumerator.c (enumerator_initialize): Warn when using deprecated form
[Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
ac7f5157ac
Коммит
c73b6bd7eb
|
@ -357,6 +357,7 @@ enumerator_initialize(int argc, VALUE *argv, VALUE obj)
|
|||
recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc());
|
||||
}
|
||||
else {
|
||||
rb_warn("Enumerator.new without a block is deprecated; use Object#to_enum");
|
||||
recv = *argv++;
|
||||
if (--argc) {
|
||||
meth = *argv++;
|
||||
|
|
|
@ -57,7 +57,10 @@ class TestEnumerator < Test::Unit::TestCase
|
|||
|
||||
def test_initialize
|
||||
assert_equal([1, 2, 3], @obj.to_enum(:foo, 1, 2, 3).to_a)
|
||||
assert_equal([1, 2, 3], Enumerator.new(@obj, :foo, 1, 2, 3).to_a)
|
||||
_, err = capture_io do
|
||||
assert_equal([1, 2, 3], Enumerator.new(@obj, :foo, 1, 2, 3).to_a)
|
||||
end
|
||||
assert_match 'Enumerator.new without a block is deprecated', err
|
||||
assert_equal([1, 2, 3], Enumerator.new { |y| i = 0; loop { y << (i += 1) } }.take(3))
|
||||
assert_raise(ArgumentError) { Enumerator.new }
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче