class Yadriggy::RubyClass

Type of immediate instances of a Ruby class. The instances of its subclass are excluded. A class type including its subclasses is represented by {CommonSuperType}.

Constants

Array
Boolean

An instance of {UnionType}. It represents either `TrueClass` or `FalseClass`.

Exception
FalseClass
Float
Hash
Integer
NilClass

The type for `nil`. Although ::NilClass is not a subtype of other classes, RubyClass::NilClass is a subtype of {RubyClass::String}, etc.

Numeric

An instance of {CommonSuperType}. It represents `::Numeric` class.

Proc
Range
String
Symbol
Table

@api private

TrueClass

Public Class Methods

[](clazz) click to toggle source

@param [Module|Object] clazz a Ruby class or module. @return [RubyClass|Object] a {RubyClass} object for `clazz`

if `clazz` is an instance of `Module`.  Otherwise, `clazz`
is returned.  For example, `RubyClass[Void]` returns `Void`.
# File lib/yadriggy/type.rb, line 317
def self.[](clazz)
  Table[clazz] || (clazz.is_a?(::Module) ? RubyClass.new(clazz) : clazz)
end
make(clazz) click to toggle source

@api private

# File lib/yadriggy/type.rb, line 302
def self.make(clazz)
  obj = RubyClass.new(clazz)
  Table[clazz] = obj
  obj
end
new(clazz) click to toggle source

@param [Module] clazz the Ruby class or module.

# File lib/yadriggy/type.rb, line 322
def initialize(clazz)
  @ruby_class = clazz
end
set_alias(clazz, ruby_class) click to toggle source

@api private

# File lib/yadriggy/type.rb, line 309
def self.set_alias(clazz, ruby_class)
  Table[clazz] = ruby_class
end

Public Instance Methods

<=(t) click to toggle source

@api private Check the subtype relation. @param [Type] t the other type. @return [Boolean] true if `self` is equivalent to `t`

or a subtype of `t`.
# File lib/yadriggy/type.rb, line 343
def <= (t)
  if t.is_super_of?(self)
    true
  else
    rc = RubyClass.role(t)
    if rc.nil?
      CommonSuperType.new(@ruby_class) <= t
    else
      rc.exact_type == @ruby_class || @ruby_class == ::NilClass
    end
  end
end
==(t) click to toggle source

Checks the equality. @param [Type|Module] t the other object. @return [Boolean] true if `self` and `t` represent the same Ruby class.

# File lib/yadriggy/type.rb, line 329
def == (t)
  RubyClass.role(t)&.exact_type == @ruby_class
end
exact_type() click to toggle source

@api private

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

@api private

# File lib/yadriggy/type.rb, line 357
def get_method_object(method_name)
  @ruby_class.instance_method(method_name)
rescue NameError
  Type.error_found!("no such method: #{@ruby_class}\##{method_name}")
end
hash() click to toggle source

@api private

# File lib/yadriggy/type.rb, line 334
def hash
  @ruby_class.hash
end
name() click to toggle source

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

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

@return [CommonSuperType] the {CommonSuperType} for this class.

# File lib/yadriggy/type.rb, line 369
def supertype
  CommonSuperType.new(@ruby_class)
end