Skip to content

Commit 74c1eab

Browse files
committed
Add a spec for evaluation of index arguments in optional assignment.
1 parent 4693f7b commit 74c1eab

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

spec/ruby/language/optional_assignments_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ def []=(k, v)
300300
(@b[:k] ||= 12).should == 12
301301
end
302302

303+
it "evaluates the index precisely once" do
304+
ary = [:x, :y]
305+
@a[:x] = 15
306+
@a[ary.pop] ||= 25
307+
ary.should == [:x]
308+
@a.should == { x: 15, y: 25 }
309+
end
310+
303311
it 'returns the assigned value, not the result of the []= method with +=' do
304312
@b[:k] = 17
305313
(@b[:k] += 12).should == 29

0 commit comments

Comments
 (0)