Skip to content

Commit a3e0151

Browse files
committed
Update Enumerator::Lazy#{chunk_while, slice_before, slice_after, slice_when} to return instances of Enumerator::Lazy
1 parent 8afebf0 commit a3e0151

File tree

6 files changed

+36
-5
lines changed

6 files changed

+36
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Bug fixes:
1515
* Clear and restore errinfo on entry and normal return from methods in C extensions (#2227).
1616
* Fix extra whitespace in squiggly heredoc with escaped newline (#2238, @wildmaples and @norswap).
1717
* Fix handling of signals with `--single-threaded` (#2265).
18+
* Fix `Enumerator::Lazy#{chunk_while, slice_before, slice_after, slice_when}` to return instances of `Enumerator::Lazy` (#2273).
1819

1920
Compatibility:
2021

spec/ruby/core/enumerator/lazy/chunk_while_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@
66
s.lazy.chunk_while { |a, b| false }.first(100).should ==
77
s.first(100).chunk_while { |a, b| false }.to_a
88
end
9+
10+
it "should return a lazy enumerator" do
11+
s = 0..Float::INFINITY
12+
s.lazy.chunk_while { |a, b| false }.should be_kind_of(Enumerator::Lazy)
13+
end
914
end

spec/ruby/core/enumerator/lazy/slice_after_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@
66
s.lazy.slice_after { |n| true }.first(100).should ==
77
s.first(100).slice_after { |n| true }.to_a
88
end
9+
10+
it "should return a lazy enumerator" do
11+
s = 0..Float::INFINITY
12+
s.lazy.slice_after { |n| true }.should be_kind_of(Enumerator::Lazy)
13+
end
914
end

spec/ruby/core/enumerator/lazy/slice_before_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@
66
s.lazy.slice_before { |n| true }.first(100).should ==
77
s.first(100).slice_before { |n| true }.to_a
88
end
9+
10+
it "should return a lazy enumerator" do
11+
s = 0..Float::INFINITY
12+
s.lazy.slice_before { |n| true }.should be_kind_of(Enumerator::Lazy)
13+
end
914
end

spec/ruby/core/enumerator/lazy/slice_when_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@
66
s.lazy.slice_when { |a, b| true }.first(100).should ==
77
s.first(100).slice_when { |a, b| true }.to_a
88
end
9+
10+
it "should return a lazy enumerator" do
11+
s = 0..Float::INFINITY
12+
s.lazy.slice_when { |a, b| true }.should be_kind_of(Enumerator::Lazy)
13+
end
914
end

src/main/ruby/truffleruby/core/enumerator.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,21 @@ def chunk(&block)
523523
super(&block).lazy
524524
end
525525

526-
# clone these methods from the superclass
527-
alias_method :chunk_while, :chunk_while
528-
alias_method :slice_after, :slice_after
529-
alias_method :slice_before, :slice_before
530-
alias_method :slice_when, :slice_when
526+
def chunk_while(&block)
527+
super(&block).lazy
528+
end
529+
530+
def slice_after(&block)
531+
super(&block).lazy
532+
end
533+
534+
def slice_before(&block)
535+
super(&block).lazy
536+
end
537+
538+
def slice_when(&block)
539+
super(&block).lazy
540+
end
531541

532542
def uniq
533543
if block_given?

0 commit comments

Comments
 (0)