sbs sbs - 1 year ago 65
Ruby Question

Safe navigation operator (&.) for nil

As Ruby 2.3 introduces the Safe navigation operator(

), a.k.a lonely operator, the behavior on
object seems odd.

nil.nil? # => true
nil&.nil? # => nil

Is that designed to behave like this way? Or some edge case that slipped away when adding the lonely operator?

mwp mwp
Answer Source

foo&.bar is shorthand for foo &&, so what would you expect the result of the expression nil && nil.nil? to be?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download