Class: NilClass
- Defined in:
- lib/active_support/core_ext/object/try.rb,
lib/active_support/core_ext/object/json.rb,
lib/active_support/core_ext/object/blank.rb,
lib/active_support/core_ext/object/to_query.rb,
lib/active_support/core_ext/object/duplicable.rb
Instance Method Summary collapse
-
#as_json(options = nil) ⇒ Object
:nodoc:.
-
#blank? ⇒ true
nil
is blank:. -
#to_param ⇒ Object
Returns
self
. -
#try(*args) ⇒ Object
Calling
try
onnil
always returnsnil
. -
#try!(*args) ⇒ Object
Calling
try!
onnil
always returnsnil
.
Instance Method Details
#as_json(options = nil) ⇒ Object
:nodoc:
78 79 80 |
# File 'lib/active_support/core_ext/object/json.rb', line 78 def as_json( = nil) #:nodoc: self end |
#blank? ⇒ true
nil
is blank:
nil.blank? # => true
54 55 56 |
# File 'lib/active_support/core_ext/object/blank.rb', line 54 def blank? true end |
#to_param ⇒ Object
Returns self
.
18 19 20 |
# File 'lib/active_support/core_ext/object/to_query.rb', line 18 def to_param self end |
#try(*args) ⇒ Object
Calling try
on nil
always returns nil
. It becomes especially helpful when navigating through associations that may return nil
.
nil.try(:name) # => nil
Without try
@person && @person.children.any? && @person.children.first.name
With try
@person.try(:children).try(:first).try(:name)
136 137 138 |
# File 'lib/active_support/core_ext/object/try.rb', line 136 def try(*args) nil end |
#try!(*args) ⇒ Object
Calling try!
on nil
always returns nil
.
nil.try!(:name) # => nil
143 144 145 |
# File 'lib/active_support/core_ext/object/try.rb', line 143 def try!(*args) nil end |