Class: Kalculator::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/kalculator/types.rb

Overview

a generic collection type of type Collection<othertype> where othertype is stored in the type instance variable

Direct Known Subclasses

List, MappedObject, String

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Collection

Returns a new instance of Collection.



17
18
19
# File 'lib/kalculator/types.rb', line 17

def initialize(type)
  @type = type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



16
17
18
# File 'lib/kalculator/types.rb', line 16

def type
  @type
end

Instance Method Details

#<=(other_object) ⇒ Object

otherobject has to be a collection, a type, or some other object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kalculator/types.rb', line 37

def <=(other_object) # otherobject has to be a collection, a type, or some other object
  if(other_object.class <= Kalculator::Collection)
    return ((self.class<= other_object.class) and (self.type <= other_object.type))
  elsif(other_object.class == Class)
    if(other_object == Object)
      return true
    end
    return false
  elsif(other_object.class != Class)
    return false
  end

  return false
end

#==(other_type) ⇒ Object

othertype has to be a collection or a type



30
31
32
33
34
35
# File 'lib/kalculator/types.rb', line 30

def ==(other_type) #othertype has to be a collection or a type
  if(other_type.class <= self.class)
      return other_type.type == self.type
  end
  return false
end

#>=(other_object) ⇒ Object

otherobject has to be a collection, a type, or some other object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kalculator/types.rb', line 52

def >=(other_object) # otherobject has to be a collection, a type, or some other object
  if(other_object.class <=Kalculator::Collection)
    return other_object<= self
  elsif(other_object.class == Class)
    return false
  elsif(other_object.class != Class)
    return false
  end

  return false
end

#generic_type?(possible_type) ⇒ Boolean

possibleType has to either be a collection or a type

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
# File 'lib/kalculator/types.rb', line 20

def generic_type?(possible_type) #possibleType has to either be a collection or a type
  if(possible_type.class <= Kalculator::Collection)
    return possible_type.type <= @type
  end
  if(possible_type.class == Class)
    return possible_type <= @type
  end
  return false
end