Class: NilClass
- Defined in:
- lib/simple_ext/object/try.rb,
lib/simple_ext/object/blank.rb,
lib/simple_ext/object/to_query.rb
Instance Method Summary collapse
-
#blank? ⇒ true
nil
is blank:. -
#to_param ⇒ Object
Returns
self
. -
#try(method_name = nil, *args) ⇒ Object
Calling
try
onnil
always returnsnil
. -
#try!(method_name = nil, *args) ⇒ Object
Calling
try!
onnil
always returnsnil
.
Instance Method Details
#blank? ⇒ true
nil
is blank:
nil.blank? # => true
55 56 57 |
# File 'lib/simple_ext/object/blank.rb', line 55 def blank? true end |
#to_param ⇒ Object
Returns self
.
20 21 22 |
# File 'lib/simple_ext/object/to_query.rb', line 20 def to_param self end |
#try(method_name = nil, *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)
117 118 119 |
# File 'lib/simple_ext/object/try.rb', line 117 def try(method_name = nil, *args) nil end |
#try!(method_name = nil, *args) ⇒ Object
Calling try!
on nil
always returns nil
.
nil.try!(:name) # => nil
124 125 126 |
# File 'lib/simple_ext/object/try.rb', line 124 def try!(method_name = nil, *args) nil end |