From a5cff7cc5de374be05db8e99c4ca975e60558a99 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Tue, 16 Nov 2021 13:43:00 -0800 Subject: Make Enumerable#each_cons return object if over size This behavior changed in dfb47bbd17c3c2b8ce17dbafaf62df023b0224b2, but only for normal exit, not for early exit. Fix it for early exit as well. While here, fix example code in documentation so that it doesn't indicate that the method returns nil. --- test/ruby/test_enum.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index b71ed54653..f6375a4ffc 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -739,6 +739,7 @@ class TestEnumerable < Test::Unit::TestCase assert_equal([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], ary) assert_equal(1..10, (1..10).each_slice(3) { }) + assert_equal([], [].each_slice(3) { }) end def test_each_cons @@ -760,6 +761,7 @@ class TestEnumerable < Test::Unit::TestCase assert_empty(ary) assert_equal(1..5, (1..5).each_cons(3) { }) + assert_equal([], [].each_cons(3) { }) end def test_zip -- cgit v1.2.3