Since ruby 2.3.0, you can call []=
method on nil
. I don't understand the purpose of this method.
For instance:
nil[1] = 1
# or
nil['foo'] = 'bar'
but []
method does not exist:
nil[1]
# => NoMethodError: undefined method `[]' for nil:NilClass
The ruby 2.3.0 changelog does not mention that changes, although it seems close to the safe navigation operator.
What is the purpose of this operator?