try(*args)
Instance Public methods
Calling try
on nil
always returns
nil
. It becomes specially helpful when navigating through
associations that may return nil
.
1 | nil .try( :name ) # => nil |
Without try
1 | @person && ! @person .children.blank? && @person .children.first.name |
With try
1 | @person .try( :children ).try( :first ).try( :name ) |
Please login to continue.