Class: Yadriggy::RubyClass
Overview
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.
Constant Summary collapse
- Symbol =
RubyClass.make(Symbol)
- String =
RubyClass.make(String)
- Integer =
RubyClass.make(Integer)
- Float =
RubyClass.make(Float)
- Rational =
RubyClass.make(Rational)
- Complex =
RubyClass.make(Complex)
- Range =
RubyClass.make(Range)
- Hash =
RubyClass.make(Hash)
- Array =
RubyClass.make(Array)
- Proc =
RubyClass.make(Proc)
- Exception =
RubyClass.make(Exception)
- TrueClass =
RubyClass.make(TrueClass)
- FalseClass =
RubyClass.make(FalseClass)
- NilClass =
The type for
nil
. Although ::NilClass is not a subtype of other classes, RubyClass::NilClass is a subtype of String, etc. RubyClass.make(NilClass)
- Boolean =
An instance of UnionType. It represents either
TrueClass
orFalseClass
. UnionType.new([RubyClass::TrueClass, RubyClass::FalseClass])
- Numeric =
An instance of CommonSuperType. It represents
::Numeric
class. CommonSuperType.new(Numeric)
Class Method Summary collapse
-
.[](clazz) ⇒ RubyClass|Object
A RubyClass object for
clazz
ifclazz
is an instance ofModule
.
Instance Method Summary collapse
-
#==(t) ⇒ Boolean
Checks the equality.
-
#initialize(clazz) ⇒ RubyClass
constructor
A new instance of RubyClass.
-
#name ⇒ String
Obtains the name of this type.
-
#supertype ⇒ CommonSuperType
The CommonSuperType for this class.
Methods inherited from Type
#!=, #copy, #eql?, error_found!, #has_role?, role
Constructor Details
#initialize(clazz) ⇒ RubyClass
Returns a new instance of RubyClass.
322 323 324 |
# File 'lib/yadriggy/type.rb', line 322 def initialize(clazz) @ruby_class = clazz end |
Class Method Details
.[](clazz) ⇒ RubyClass|Object
Returns a Yadriggy::RubyClass object for clazz
if clazz
is an instance of Module
. Otherwise, clazz
is returned. For example, RubyClass[Void]
returns Void
.
317 318 319 |
# File 'lib/yadriggy/type.rb', line 317 def self.[](clazz) Table[clazz] || (clazz.is_a?(::Module) ? RubyClass.new(clazz) : clazz) end |
Instance Method Details
#==(t) ⇒ Boolean
Checks the equality.
329 330 331 |
# File 'lib/yadriggy/type.rb', line 329 def == (t) RubyClass.role(t)&.exact_type == @ruby_class end |
#name ⇒ String
Obtains the name of this type.
375 376 377 |
# File 'lib/yadriggy/type.rb', line 375 def name @ruby_class.name end |
#supertype ⇒ CommonSuperType
Returns the CommonSuperType for this class.
369 370 371 |
# File 'lib/yadriggy/type.rb', line 369 def supertype CommonSuperType.new(@ruby_class) end |