class Yadriggy::Type

@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`.

Public Class Methods

error_found!(msg) click to toggle source

Raises an error. @param [String] msg an error message.

# File lib/yadriggy/type.rb, line 18
def self.error_found!(msg)
  raise TypeChecker::CheckError.new(msg)
end
get_instance_method_object(recv_type, method_name) click to toggle source

@api private

# File lib/yadriggy/type.rb, line 12
def self.get_instance_method_object(recv_type, method_name)
  recv_type.get_method_object(method_name)
end
role(type) click to toggle source

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

@param [Type] type a Type object. @return [Type|nil] an instance of the receiver class.

# File lib/yadriggy/type.rb, line 70
def self.role(type)
  if type.is_a?(Type)
    type.has_role?(self)
  else
    nil
  end
end

Public Instance Methods

!=(t) click to toggle source

Check the inequality. @return [Boolean] false if `self` and `t` represent the same type.

# File lib/yadriggy/type.rb, line 40
def != (t)
  !(self == t)
end
<=(t) click to toggle source

Check the subtype relation. @param [Type] t the other type. @return [Boolean] true if `self` is equivalent to `t` or a subtpye of `t`

# File lib/yadriggy/type.rb, line 53
def <= (t)
  self == t
end
copy(without_role) click to toggle source

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

@param [Class] without_role a subclass of {OptionalRole}. @return [Type] the copy.

# File lib/yadriggy/type.rb, line 34
def copy(without_role)
  self
end
eql?(t) click to toggle source

An alias to `==`. @return [Boolean] true if `self` and `t` represent the same type.

# File lib/yadriggy/type.rb, line 46
def eql?(t)
  self == t
end
exact_type() click to toggle source

Gets the Ruby class represented by this Type. @return [Module|DynType] the corresponding Ruby class or {DynType}.

# File lib/yadriggy/type.rb, line 95
def exact_type
  DynType
end
get_method_object(method_name) click to toggle source

@api private Gets a method with the given name declared in this type. `nil` is returned when the method is not exactly determined.

@return [Method|nil]

# File lib/yadriggy/type.rb, line 104
def get_method_object(method_name)
  nil
end
has_role?(a_role) click to toggle source

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}.

@param [Module] a_role a subclass of Type. @return [Type|nil] an instance of `a_role`.

# File lib/yadriggy/type.rb, line 85
def has_role?(a_role)
  if self.is_a?(a_role)
    self
  else
    nil
  end
end
is_super_of?(t) click to toggle source

@api private Only {DynType}, {UnionType} and {OptionalRole} override this method.

# File lib/yadriggy/type.rb, line 59
def is_super_of? (t)
  false
end
name() click to toggle source

Obtains the name of this type. @return [String] the type name.

# File lib/yadriggy/type.rb, line 24
def name()
  to_s
end
supertype() click to toggle source

@return [Type] the type containing a wider range of values.

# File lib/yadriggy/type.rb, line 109
def supertype
  nil
end