Ruby 2.3.0 introduces the safe navigation syntax that eases the nil handling of chained method calls by introducing a new operator that only calls the method if value of previous statement is not nil. This is a feature that already exists for example in C#, Groovy and Swift. For example in Groovy, the syntax is
foo?.bar
which basically means that the result value is that of foo.bar unless foo is null, in which case the return value is also null and thus no exception is thrown. Also C# (called null-conditional operators) and Swift (called optional-chaining expression) use this notation.
So the syntax seems to be quite standard in other languages. Now, why in Ruby the syntax is
foo&.bar
instead?
foo?.bar
means "call methodfoo?
, then call methodbar
on the result". 2.3.0 is a backwards-compatible release, your proposed syntax would result in massive breakage, it would at least need a couple of years deprecation warning before it could be introduced.