Ruby's Safe Navigation Operator

A little post about the safe nav operator

Ruby's safe navigation operator is used to access a method on an object that might be undefined. Say we want to get the full address of a user's company. It would look something like this:

But what if not all users have a company? The would be nil. And then we would be trying to access the method full_address on a nil value. Ultimately we would be left with the following error: Undefined method `full_address' for nil:NilClass

We can use a safe navigation operator to prevent this error. We would write This would allow us to get the full_address, only if the was not nil.