Ruby 3 · Basics

Handle nil safely

&. calls a method only if the receiver is not nil.

city = user&.dig(:address, :city)

Official Ruby 3 documentation

More basics commands

All basics commands · Ruby 3 cheatsheet

Was this page helpful?