Class: Yadriggy::Type Abstract
- Inherits:
-
Object
- Object
- Yadriggy::Type
- Defined in:
- lib/yadriggy/type.rb
Overview
Direct Known Subclasses
CommonSuperType, CompositeType, InstanceType, MethodType, OptionalRole, RubyClass, UnionType
Class Method Summary collapse
-
.error_found!(msg) ⇒ Object
Raises an error.
-
.role(type) ⇒ Type|nil
Finds an instance of the receiver class in the chain starting with the given Type object.
Instance Method Summary collapse
-
#!=(t) ⇒ Boolean
Check the inequality.
-
#<=(t) ⇒ Boolean
Check the subtype relation.
-
#copy(without_role) ⇒ Type
Makes a copy of self.
-
#eql?(t) ⇒ Boolean
An alias to
==. -
#exact_type ⇒ Module|DynType
Gets the Ruby class represented by this Type.
-
#has_role?(a_role) ⇒ Type|nil
Finds an instance of the receiver class in the chain starting with
self. -
#name ⇒ String
Obtains the name of this type.
-
#supertype ⇒ Type
The type containing a wider range of values.
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_type ⇒ Module|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 |
#name ⇒ String
Obtains the name of this type.
24 25 26 |
# File 'lib/yadriggy/type.rb', line 24 def name() to_s end |
#supertype ⇒ Type
Returns the type containing a wider range of values.
109 110 111 |
# File 'lib/yadriggy/type.rb', line 109 def supertype nil end |