Skip to content

Commit b46bd15

Browse files
committed
Add some specs for swapping with multiple assignment
1 parent 0aac1eb commit b46bd15

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

spec/ruby/language/variables_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,18 @@ module VariableSpecs
715715
x.should == [1, 2, 3, 4, 5]
716716
end
717717

718+
it "can be used to swap array elements" do
719+
a = [1, 2]
720+
a[0], a[1] = a[1], a[0]
721+
a.should == [2, 1]
722+
end
723+
724+
it "can be used to swap range of array elements" do
725+
a = [1, 2, 3, 4]
726+
a[0, 2], a[2, 2] = a[2, 2], a[0, 2]
727+
a.should == [3, 4, 1, 2]
728+
end
729+
718730
it "assigns RHS values to LHS constants" do
719731
module VariableSpecs
720732
MRHS_VALUES_1, MRHS_VALUES_2 = 1, 2

0 commit comments

Comments
 (0)