Class: NilClass
- Defined in:
- lib/gorillib/object/blank.rb,
lib/gorillib/object/try.rb,
lib/gorillib/serialization.rb,
lib/gorillib/object/try_dup.rb
Overview
class Numeric
Instance Method Summary collapse
-
#blank? ⇒ TrueClass
Nil is always blank.
- #to_wire(options = {}) ⇒ Object
-
#try(*args) ⇒ Object
Calling
try
onnil
always returnsnil
. - #try_dup ⇒ Object
Instance Method Details
#blank? ⇒ TrueClass
Nil is always blank
nil.blank? #=> true
52 53 54 |
# File 'lib/gorillib/object/blank.rb', line 52 def blank? true end |
#to_wire(options = {}) ⇒ Object
51 52 53 |
# File 'lib/gorillib/serialization.rb', line 51 def to_wire(={}) nil end |
#try(*args) ⇒ Object
Calling try
on nil
always returns nil
. It becomes specially helpful when navigating through associations that may return nil
.
Examples
nil.try(:name) # => nil
Without try
@person && !@person.children.blank? && @person.children.first.name
With try
@person.try(:children).try(:first).try(:name)
53 54 55 |
# File 'lib/gorillib/object/try.rb', line 53 def try(*args) nil end |
#try_dup ⇒ Object
29 30 31 |
# File 'lib/gorillib/object/try_dup.rb', line 29 def try_dup self end |