Class: PresentClass

Inherits:
Object show all
Defined in:
lib/tektite_ruby_utils/present.rb

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

Instance Method Summary collapse

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

#typeObject (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

#inspectObject

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_aObject

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_iObject

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_sObject

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.

Returns:

  • (Boolean)


40
41
42
# File 'lib/tektite_ruby_utils/present.rb', line 40

def type_known?
  @type.nil? ? false : true
end