aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--enumerator.c1
-rw-r--r--test/ruby/test_enumerator.rb5
2 files changed, 5 insertions, 1 deletions
diff --git a/enumerator.c b/enumerator.c
index f01ddd51e6..d5d276f6aa 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -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++;
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
index 8b33a5e826..6b8a09f80f 100644
--- a/test/ruby/test_enumerator.rb
+++ b/test/ruby/test_enumerator.rb
@@ -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