Skip to content

Commit

Permalink
Merge pull request #1159 from herwinw/language_for
Browse files Browse the repository at this point in the history
Additional specs for destructuring in for loops
  • Loading branch information
andrykonchin committed Jun 15, 2024
2 parents d70c812 + 5b77a49 commit 8ee7706
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions language/for_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@
end
end

it "iterates over a list of arrays and destructures with an empty splat" do
for i, * in [[1,2]]
i.should == 1
end
end

it "iterates over a list of arrays and destructures with a splat" do
for i, *j in [[1,2]]
i.should == 1
j.should == [2]
end
end

it "iterates over a list of arrays and destructures with a splat and additional targets" do
for i, *j, k in [[1,2,3,4]]
i.should == 1
j.should == [2,3]
k.should == 4
end
end

it "iterates over an Hash passing each key-value pair to the block" do
k = 0
l = 0
Expand Down

0 comments on commit 8ee7706

Please sign in to comment.