> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/ruby/safe-navigation-operator.md).

# Safe Navigation Operator

With the release of Ruby 2.3, the *safe navigation operator* (`&.`) is now available. This addition to the Ruby language allows you to collapse all those pesky `nil` checks into the accessor call they are guarding. Consider this snippet of common Ruby code:

```ruby
if user && user.authenticate(params[:password])
  # proceed with logged in user
end
```

With the *safe navigation operator*, the predicate can now be collapsed:

```ruby
if user&.authenticate(params[:password])
  # proceed with logged in user
end
```

If `user` is `nil`, then the predicate will evaluate to `false` and the body of the if-statement will be passed over.

[Source](http://nithinbekal.com/posts/ruby-2-3-features/)
