Class: Dux::NullObject
- Inherits:
-
Object
- Object
- Dux::NullObject
- Includes:
- InspectID
- Defined in:
- lib/dux/null_object.rb
Overview
Null objects that can be used for smarter argument building.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of this null object, for self-documenting / introspection.
-
#purpose ⇒ String
readonly
A purpose or description of this object, for self-documenting / introspection.
Instance Method Summary collapse
-
#default_name ⇒ String
private
Generates a default name for this object.
-
#initialize(name = nil, purpose: 'a null object') ⇒ NullObject
constructor
A new instance of NullObject.
-
#inspect_id(object = self) ⇒ String
included
from InspectID
Calculates the id shown in the default version of
#inspect
methods.
Constructor Details
#initialize(name = nil, purpose: 'a null object') ⇒ NullObject
Returns a new instance of NullObject.
45 46 47 48 49 50 |
# File 'lib/dux/null_object.rb', line 45 def initialize(name = nil, purpose: 'a null object') @name = name || default_name @purpose = purpose freeze end |
Instance Attribute Details
#name ⇒ String (readonly)
The name of this null object, for self-documenting / introspection.
In practice, this should be the object path,
e.g. Foo::Bar::NULL
35 36 37 |
# File 'lib/dux/null_object.rb', line 35 def name @name end |
#purpose ⇒ String (readonly)
A purpose or description of this object, for self-documenting / introspection.
41 42 43 |
# File 'lib/dux/null_object.rb', line 41 def purpose @purpose end |
Instance Method Details
#default_name ⇒ String (private)
Generates a default name for this object.
57 58 59 |
# File 'lib/dux/null_object.rb', line 57 def default_name "Dux::NullObject(#{inspect_id(self)})" end |
#inspect_id(object = self) ⇒ String Originally defined in module InspectID
This is currently limited to the implementation used in MRI. Rubinius and JRuby have their own implementations that are not currently served by this.
Calculates the id shown in the default
version of #inspect
methods.