I've just noticed a very puzzling change in behaviour between Ruby 2.2.4 and Ruby 2.3.0: trying to use [] on nil in an assignment does not raise a NoMethodError anymore.
Ruby 2.2.4:
box:~ jfoeh$ irb
2.2.4 :001 > a = nil
=> nil
2.2.4 :002 > a[:b] = 1
NoMethodError: undefined method `[]=' for nil:NilClass
from (irb):2
from /Users/jfoeh/.rvm/rubies/ruby-2.2.4/bin/irb:11:in `<main>'
In contrast Ruby 2.3.0:
box:~ jfoeh$ irb
2.3.0 :001 > a = nil
=> nil
2.3.0 :002 > a[:b] = 1
=> nil
Is that behaviour expected, or is this a regression of sorts?
We originally noticed this when we found such an assignment seemingly swallowing exceptions in 2.3:
2.3.0 :001 > require 'date'
=> true
2.3.0 :002 > a = nil
=> nil
2.3.0 :003 > a[:b] = Date.parse(nil)
=> nil
whereas Ruby 2.2 would execute the right-hand side first and raise a TypeError as one would expect.