Ruby Tips

Safe Navigation Operator

Safe navigation operator returns nil if a method is called on a nil object:

account&.owner&.name #=> nil

account = Account.create!
Owner.create(name: 'steve' account: account)

account&.owner&.name #=> 'steve'

Ruby Tips - a simple ruby tip generator

Refresh the page to generate a new tip. Or just click here

Built by @zayneabraham

RubyTips - A random Ruby tip generator | Product Hunt Embed