Class: Yadriggy::Type Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/yadriggy/type.rb

Overview

This class is abstract.

Root of the classes representing a type. A Type object may consist of a chain of multiple Type objects.

Don't use is_a? but use has_role? or role.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.error_found!(msg) ⇒ Object

Raises an error.



18
19
20
# File 'lib/yadriggy/type.rb', line 18

def self.error_found!(msg)
  raise TypeChecker::CheckError.new(msg)
end

.role(type) ⇒ Type|nil

Finds an instance of the receiver class in the chain starting with the given Yadriggy::Type object. If such an instance is not found, the method returns nil. Also see OptionalRole.



70
71
72
73
74
75
76
# File 'lib/yadriggy/type.rb', line 70

def self.role(type)
  if type.is_a?(Type)
    type.has_role?(self)
  else
    nil
  end
end

Instance Method Details

#!=(t) ⇒ Boolean

Check the inequality.



40
41
42
# File 'lib/yadriggy/type.rb', line 40

def != (t)
  !(self == t)
end

#<=(t) ⇒ Boolean

Check the subtype relation.



53
54
55
# File 'lib/yadriggy/type.rb', line 53

def <= (t)
  self == t
end

#copy(without_role) ⇒ Type

Makes a copy of self. Note that a Yadriggy::Type object may consist of a chain of multiple Yadriggy::Type objects. The copied chain does not contain an instance of without_role.



34
35
36
# File 'lib/yadriggy/type.rb', line 34

def copy(without_role)
  self
end

#eql?(t) ⇒ Boolean

An alias to ==.



46
47
48
# File 'lib/yadriggy/type.rb', line 46

def eql?(t)
  self == t
end

#exact_typeModule|DynType

Gets the Ruby class represented by this Type.



95
96
97
# File 'lib/yadriggy/type.rb', line 95

def exact_type
  DynType
end

#has_role?(a_role) ⇒ Type|nil

Finds an instance of the receiver class in the chain starting with self. If such an instance is not found, the method returns nil. Also see OptionalRole.



85
86
87
88
89
90
91
# File 'lib/yadriggy/type.rb', line 85

def has_role?(a_role)
  if self.is_a?(a_role)
    self
  else
    nil
  end
end

#nameString

Obtains the name of this type.



24
25
26
# File 'lib/yadriggy/type.rb', line 24

def name()
  to_s
end

#supertypeType



109
110
111
# File 'lib/yadriggy/type.rb', line 109

def supertype
  nil
end