Class: NullClass
- Includes:
- Falsiness, RecursiveMethodMissing, TruthyBooleanOperators
- Defined in:
- lib/null.rb
Overview
We implement the Null Object Pattern, i.e. most methods called on us will return self. Also, boolean logical operators for true, false, and nil have been redefined so that they depend on the falsy?
Direct Known Subclasses
Instance Method Summary collapse
-
#coerce(x) ⇒ Object
Make Numeric operations involving
nullreturnnull. -
#empty? ⇒ Boolean
:nodoc:.
-
#inspect ⇒ Object
“null”.
-
#nil? ⇒ Boolean
:nodoc:.
-
#null? ⇒ Boolean
:nodoc:.
-
#present? ⇒ Boolean
:nodoc:.
-
#tap? ⇒ Boolean
Require a block, but don’t use it; then return
self. -
#to_nil? ⇒ Boolean
:nodoc:.
-
#to_s ⇒ Object
“”.
Methods included from RecursiveMethodMissing
Methods included from TruthyBooleanOperators
Methods included from Falsiness
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RecursiveMethodMissing
Instance Method Details
#coerce(x) ⇒ Object
Make Numeric operations involving null return null.
148 149 150 |
# File 'lib/null.rb', line 148 def coerce(x) [null, null] end |
#empty? ⇒ Boolean
:nodoc:
136 |
# File 'lib/null.rb', line 136 def empty?() true end |
#nil? ⇒ Boolean
:nodoc:
134 |
# File 'lib/null.rb', line 134 def nil?() true end |
#null? ⇒ Boolean
:nodoc:
135 |
# File 'lib/null.rb', line 135 def null?() true end |
#present? ⇒ Boolean
:nodoc:
139 |
# File 'lib/null.rb', line 139 def present?() false end |
#tap? ⇒ Boolean
Require a block, but don’t use it; then return self.
142 143 144 145 |
# File 'lib/null.rb', line 142 def tap? # :nodoc: raise(LocalJumpError, 'no block given') unless block_given? self end |
#to_nil? ⇒ Boolean
:nodoc:
137 |
# File 'lib/null.rb', line 137 def to_nil?() nil end |