Class: YardTypes::KindType
Overview
A KindType constraint is specified as SomeModule or SomeClass, and indicates that the object must be a kind of that module.
Instance Attribute Summary
Attributes inherited from Type
Instance Method Summary collapse
-
#check(obj) ⇒ Boolean
Type checks a given object.
-
#constant ⇒ Module
The constant specified by
name.
Methods inherited from Type
Constructor Details
This class inherits a constructor from YardTypes::Type
Instance Method Details
#check(obj) ⇒ Boolean
Type checks a given object. Special consideration is given to the pseudo-class Boolean, which does not actually exist in Ruby, but is commonly used to mean TrueClass, FalseClass.
112 113 114 115 116 117 118 |
# File 'lib/yard_types/types.rb', line 112 def check(obj) if name == 'Boolean' obj == true || obj == false else obj.kind_of? constant end end |
#constant ⇒ Module
Returns the constant specified by name.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/yard_types/types.rb', line 123 def constant @constant ||= begin const = name.split('::').reduce(Object) { |namespace, const| namespace.const_get(const) } unless const.kind_of?(Module) raise TypeError, "class or module required; #{name} is a #{const.class}" end const end end |