Class: NullObject
Overview
Null object pattern implementation in YSupport. apart from the expected null object behavior (such as returning self in response to almost all messages), this null object instances can carry a signature specified by the user upon creation, which can serve to hint the origin of the null object. (This signature is opional, default is nil
.)
Instance Attribute Summary collapse
-
#null_object_signature ⇒ Object
readonly
Returns the value of attribute null_object_signature.
Instance Method Summary collapse
-
#==(other) ⇒ Object
True if and only if the other object is a NullObject with same signature.
-
#blank? ⇒ Boolean
Always true.
-
#empty? ⇒ Boolean
Always true.
-
#initialize(null_object_signature = nil) ⇒ NullObject
constructor
Signature can be given as an optional argument upon initialization.
-
#inspect ⇒ Object
Inspection string.
-
#method_missing(ß, *args, &block) ⇒ Object
:nodoc:.
-
#null_object?(signature = nil) ⇒ Boolean
(also: #null?)
Inquirer whether an object is a NullObject.
-
#present? ⇒ Boolean
Always false.
-
#respond_to?(ß, *args, &block) ⇒ Boolean
:nodoc:.
-
#to_a ⇒ Object
Empty array.
-
#to_f ⇒ Object
Float zero.
-
#to_i ⇒ Object
Integer zero.
-
#to_s ⇒ Object
Description string.
Constructor Details
#initialize(null_object_signature = nil) ⇒ NullObject
Signature can be given as an optional argument upon initialization.
16 17 18 |
# File 'lib/y_support/null_object.rb', line 16 def initialize null_object_signature=nil @null_object_signature = null_object_signature end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(ß, *args, &block) ⇒ Object
:nodoc:
70 71 72 |
# File 'lib/y_support/null_object.rb', line 70 def method_missing ß, *args, &block # :nodoc: self end |
Instance Attribute Details
#null_object_signature ⇒ Object (readonly)
Returns the value of attribute null_object_signature.
12 13 14 |
# File 'lib/y_support/null_object.rb', line 12 def null_object_signature @null_object_signature end |
Instance Method Details
#==(other) ⇒ Object
True if and only if the other object is a NullObject with same signature.
65 66 67 68 |
# File 'lib/y_support/null_object.rb', line 65 def == other other.is_a?( self.class ) && other.null_object_signature == null_object_signature end |
#blank? ⇒ Boolean
Always true.
61 |
# File 'lib/y_support/null_object.rb', line 61 def blank?; true end |
#empty? ⇒ Boolean
Always true.
57 |
# File 'lib/y_support/null_object.rb', line 57 def empty?; true end |
#inspect ⇒ Object
Inspection string.
41 |
# File 'lib/y_support/null_object.rb', line 41 def inspect; to_s end |
#null_object?(signature = nil) ⇒ Boolean Also known as: null?
Inquirer whether an object is a NullObject. Again, optional signature argument can be given to distinguish between different null objects.
23 24 25 |
# File 'lib/y_support/null_object.rb', line 23 def null_object? signature=nil null_object_signature == signature end |
#present? ⇒ Boolean
Always false.
53 |
# File 'lib/y_support/null_object.rb', line 53 def present?; false end |
#respond_to?(ß, *args, &block) ⇒ Boolean
:nodoc:
74 75 76 |
# File 'lib/y_support/null_object.rb', line 74 def respond_to? ß, *args, &block # :nodoc: true end |
#to_s ⇒ Object
Description string.
34 35 36 37 |
# File 'lib/y_support/null_object.rb', line 34 def to_s sgn = null_object_signature sgn.nil? ? "#<NullObject>" : "#<NullObject #{sgn}>" end |