class NilClass

def self.add_whiner(klass)

def self.add_whiner(klass)
  ActiveSupport::Deprecation.warn "NilClass.add_whiner is deprecated and this functionality is " \
    "removed from Rails versions as it affects Ruby 1.9 performance.", caller
end

def as_json(options = nil) self end #:nodoc:

:nodoc:
def as_json(options = nil) self end #:nodoc:

def blank?


nil.blank? # => true

+nil+ is blank:
def blank?
  true
end

def duplicable?


nil.dup # => TypeError: can't dup NilClass
nil.duplicable? # => false

+nil+ is not duplicable:
def duplicable?
  false
end

def encode_json(encoder) 'null' end #:nodoc:

:nodoc:
:nodoc:
def encode_json(encoder) 'null' end #:nodoc:

def id

Raises a RuntimeError when you attempt to call +id+ on +nil+.
def id
  raise RuntimeError, "Called id for nil, which would mistakenly be #{object_id} -- if you really wanted the id of nil, use object_id", caller
end

def to_param

def to_param
  self
end

def try(*args)

@person.try(:children).try(:first).try(:name)
With +try+

@person && !@person.children.blank? && @person.children.first.name
Without +try+

nil.try(:name) # => nil

=== Examples

It becomes specially helpful when navigating through associations that may return +nil+.
Calling +try+ on +nil+ always returns +nil+.
def try(*args)
  nil
end