Class: PresentClass
Overview
PresentClass should behave just as NilClass, but the opposite. It represents that a value exists but does not represent any specific vallue or type; it is ambiguous. present should be seen as the opposite of nil.
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type = nil) ⇒ PresentClass
constructor
typeshould be either nil (for ambiguous) or the class of the object represented. -
#inspect ⇒ Object
Makes present appear and behave like nil in the console.
-
#to_a ⇒ Object
present can not be converted to an Array.
-
#to_i ⇒ Object
present can not be converted to an Integer.
-
#to_s ⇒ Object
present can not be converted to a String.
-
#type_known? ⇒ Boolean
Return true if the object type is defined.
Constructor Details
#initialize(type = nil) ⇒ PresentClass
type should be either nil (for ambiguous) or the class of the object represented.
9 10 11 |
# File 'lib/tektite_ruby_utils/present.rb', line 9 def initialize(type = nil) @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/tektite_ruby_utils/present.rb', line 5 def type @type end |
Instance Method Details
#inspect ⇒ Object
Makes present appear and behave like nil in the console. To see the object id, use .object_id. To see the value of an attribute such as @type, use the attribute getter method, such as .type.
16 17 18 |
# File 'lib/tektite_ruby_utils/present.rb', line 16 def inspect 'present' end |
#to_a ⇒ Object
present can not be converted to an Array.
30 31 32 |
# File 'lib/tektite_ruby_utils/present.rb', line 30 def to_a raise AmbiguousValueError end |
#to_i ⇒ Object
present can not be converted to an Integer.
25 26 27 |
# File 'lib/tektite_ruby_utils/present.rb', line 25 def to_i raise AmbiguousValueError end |
#to_s ⇒ Object
present can not be converted to a String.
35 36 37 |
# File 'lib/tektite_ruby_utils/present.rb', line 35 def to_s raise AmbiguousValueError end |
#type_known? ⇒ Boolean
Return true if the object type is defined.
40 41 42 |
# File 'lib/tektite_ruby_utils/present.rb', line 40 def type_known? @type.nil? ? false : true end |