Nil is always blank
nil.blank? #=> true
@return [TrueClass]
# File lib/gorillib/object/blank.rb, line 52 def blank? true end
# File lib/gorillib/serialization/to_wire.rb, line 51 def to_wire(options={}) nil end
Calling try on nil always returns nil. It becomes specially helpful when navigating through associations that may return nil.
nil.try(:name) # => nil
Without try
@person && !@person.children.blank? && @person.children.first.name
With try
@person.try(:children).try(:first).try(:name)
# File lib/gorillib/object/try.rb, line 53 def try(*args) nil end
Generated with the Darkfish Rdoc Generator 2.