class NilClass
def as_json(options = nil) #:nodoc:
def as_json(options = nil) #:nodoc: self end
def blank?
+nil+ is blank:
def blank? true end
def duplicable?
nil.duplicable? # => false
+nil+ is not duplicable:
def duplicable? false end
def encode_json(encoder) #:nodoc:
def encode_json(encoder) #:nodoc: 'null' end
def to_param
def to_param self end
def try(*args)
With +try+
@person && !@person.children.blank? && @person.children.first.name
Without +try+
nil.try(:name) # => nil
It becomes specially helpful when navigating through associations that may return +nil+.
Calling +try+ on +nil+ always returns +nil+.
def try(*args) nil end
def try!(*args)
def try!(*args) nil end