We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 67ce7af commit 3186b2fCopy full SHA for 3186b2f
spec/ruby/language/optional_assignments_spec.rb
@@ -312,6 +312,32 @@ def []=(k, v)
312
@a.should == { x: 15, y: 25 }
313
end
314
315
+ it "evaluates the index arguments in the correct order" do
316
+ ary = Class.new(Array) do
317
+ def [](x, y)
318
+ super(x + 3 * y)
319
+ end
320
+
321
+ def []=(x, y, value)
322
+ super(x + 3 * y, value)
323
324
+ end.new
325
+ ary[0, 0] = 1
326
+ ary[1, 0] = 1
327
+ ary[2, 0] = nil
328
+ ary[3, 0] = 1
329
+ ary[4, 0] = 1
330
+ ary[5, 0] = 1
331
+ ary[6, 0] = nil
332
333
+ foo = [0, 2]
334
335
+ ary[foo.pop, foo.pop] ||= 2
336
337
+ ary[2, 0].should == 2
338
+ ary[6, 0].should == nil
339
340
341
it 'returns the assigned value, not the result of the []= method with +=' do
342
@b[:k] = 17
343
(@b[:k] += 12).should == 29
0 commit comments