Class: YardTypes::Type Abstract

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

Overview

This class is abstract.

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


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

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameString


60
61
62
# File 'lib/yard_types/types.rb', line 60

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.


65
66
67
68
69
70
71
72
73
74
# File 'lib/yard_types/types.rb', line 65

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.

Raises:

  • (NotImplementedError)

    must be handled by the subclasses.


94
95
96
# File 'lib/yard_types/types.rb', line 94

def check(obj)
  raise NotImplementedError
end

#descriptionString

Returns an English phrase describing this type.

Raises:

  • (NotImplementedError)

87
88
89
# File 'lib/yard_types/types.rb', line 87

def description
  raise NotImplementedError
end

#to_sString


82
83
84
# File 'lib/yard_types/types.rb', line 82

def to_s
  name
end