Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby 3.1: Enumerable#each_cons and each_slice to return a receiver #954

Merged
merged 2 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/enumerable/each_cons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
multi.each_cons(2).to_a.should == [[[1, 2], [3, 4, 5]], [[3, 4, 5], [6, 7, 8, 9]]]
end

ruby_version_is "3.1" do
it "returns self when a block is given" do
@enum.each_cons(3){}.should == @enum
end
end

describe "when no block is given" do
it "returns an enumerator" do
e = @enum.each_cons(3)
Expand Down
6 changes: 6 additions & 0 deletions core/enumerable/each_slice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
e.to_a.should == @sliced
end

ruby_version_is "3.1" do
it "returns self when a block is given" do
@enum.each_slice(3){}.should == @enum
end
end

it "gathers whole arrays as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
multi.each_slice(2).to_a.should == [[[1, 2], [3, 4, 5]], [[6, 7, 8, 9]]]
Expand Down