Method: YardTypes::KindType#constant

Defined in:
lib/yard_types/types.rb

#constantModule

Returns the constant specified by name.

Returns:

  • (Module)

    the constant specified by name.

Raises:

  • (TypeError)

    if the constant is neither a module nor a class

  • (NameError)

    if the specified constant could not be loaded.



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