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. -
#description ⇒ String
An English phrase describing this type.
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.
135 136 137 138 139 140 141 |
# File 'lib/yard_types/types.rb', line 135 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.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/yard_types/types.rb', line 151 def constant @constant ||= begin const = name.split('::').reduce(Object) { |namespace, inner_const| namespace.const_get(inner_const) } unless const.kind_of?(Module) raise TypeError, "class or module required; #{name} is a #{const.class}" end const end end |
#description ⇒ String
Returns an English phrase describing this type.
144 145 146 |
# File 'lib/yard_types/types.rb', line 144 def description name end |