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
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
@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
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
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
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
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
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
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
@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
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
@api private Only {DynType}, {UnionType} and {OptionalRole} override this method.
# File lib/yadriggy/type.rb, line 59 def is_super_of? (t) false end
Obtains the name of this type. @return [String] the type name.
# File lib/yadriggy/type.rb, line 24 def name() to_s end
@return [Type] the type containing a wider range of values.
# File lib/yadriggy/type.rb, line 109 def supertype nil end