Skip to content

Commit 0bf24bd

Browse files
committed
Cleanup Array#each specs
1 parent 45dd5e7 commit 0bf24bd

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

spec/ruby/core/array/each_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Mutating the array while it is being iterated is discouraged as it can result in confusing behavior.
77
# Yet a Ruby implementation must not crash in such a case, and following the simple CRuby behavior makes sense.
8-
# CRuby simply reads the array storage and check the size for every iteration;
8+
# CRuby simply reads the array storage and checks the size for every iteration;
99
# like `i = 0; while i < size; yield self[i]; end`
1010

1111
describe "Array#each" do
@@ -18,23 +18,23 @@
1818

1919
it "yields each element to the block even if the array is changed during iteration" do
2020
a = [1, 2, 3, 4, 5]
21-
b = []
22-
a.each {|x| b << x; a << x+5 if (x%2).zero? }
23-
b.should == [1, 2, 3, 4, 5, 7, 9]
21+
iterated = []
22+
a.each { |x| iterated << x; a << x+5 if x.even? }
23+
iterated.should == [1, 2, 3, 4, 5, 7, 9]
2424
end
2525

2626
it "yields only elements that are still in the array" do
2727
a = [0, 1, 2, 3, 4]
28-
b = []
29-
a.each {|x| b << x; a.pop if (x%2).zero? }
30-
b.should == [0, 1, 2]
28+
iterated = []
29+
a.each { |x| iterated << x; a.pop if x.even? }
30+
iterated.should == [0, 1, 2]
3131
end
3232

3333
it "yields elements based on an internal index" do
3434
a = [0, 1, 2, 3, 4]
35-
b = []
36-
a.each {|x| b << x; a.shift if (x%2).zero? }
37-
b.should == [0, 2, 4]
35+
iterated = []
36+
a.each { |x| iterated << x; a.shift if x.even? }
37+
iterated.should == [0, 2, 4]
3838
end
3939

4040
it "yields each element to a block that takes multiple arguments" do

0 commit comments

Comments
 (0)