Class: YardTypes::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/yard_types/types.rb

Overview

The base class for all supported types.

Direct Known Subclasses

CollectionType, DuckType, HashType, KindType, LiteralType

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Type

Returns a new instance of Type.

Parameters:

  • name (String)


64
65
66
# File 'lib/yard_types/types.rb', line 64

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameString

Returns:

  • (String)


47
48
49
# File 'lib/yard_types/types.rb', line 47

def name
  @name
end

Class Method Details

.for(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO:

This interface was just hacked into place while enhancing the parser to return DuckType, KindType, etc.



52
53
54
55
56
57
58
59
60
61
# File 'lib/yard_types/types.rb', line 52

def self.for(name)
  case name
  when /^#/
    DuckType.new(name)
  when *LiteralType.names
    LiteralType.new(name)
  else
    KindType.new(name)
  end
end

Instance Method Details

#check(obj) ⇒ Boolean

Returns whether the object is of this type.

Parameters:

  • obj (Object)

    Any object.

Returns:

  • (Boolean)

    whether the object is of this type.

Raises:

  • (NotImplementedError)

    must be handled by the subclasses.



76
77
78
# File 'lib/yard_types/types.rb', line 76

def check(obj)
  raise NotImplementedError
end

#to_sString

Returns a YARD type string describing this type.

Returns:

  • (String)

    a YARD type string describing this type.



69
70
71
# File 'lib/yard_types/types.rb', line 69

def to_s
  name
end