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_null? ⇒ 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.
158 159 160 |
# File 'lib/null.rb', line 158 def coerce(x) [null, null] end |
#empty? ⇒ Boolean
:nodoc:
145 |
# File 'lib/null.rb', line 145 def empty?() true end |
#nil? ⇒ Boolean
:nodoc:
143 |
# File 'lib/null.rb', line 143 def nil?() true end |
#null? ⇒ Boolean
:nodoc:
144 |
# File 'lib/null.rb', line 144 def null?() true end |
#present? ⇒ Boolean
:nodoc:
148 |
# File 'lib/null.rb', line 148 def present?() false end |
#tap? ⇒ Boolean
Require a block, but don’t use it; then return self.
152 153 154 155 |
# File 'lib/null.rb', line 152 def tap? # :nodoc: raise(LocalJumpError, 'no block given') unless block_given? self end |
#to_nil? ⇒ Boolean
:nodoc:
146 |
# File 'lib/null.rb', line 146 def to_nil?() nil end |
#to_null? ⇒ Boolean
:nodoc:
149 |
# File 'lib/null.rb', line 149 def to_null?() null end |