Class: YardTypes::TypeConstraint
- Inherits:
-
Object
- Object
- YardTypes::TypeConstraint
- Defined in:
- lib/yard_types/types.rb
Overview
A TypeConstraint specifies the set of acceptable types which can satisfy the constraint. Parsing any YARD type description will return a TypeConstraint instance.
Instance Attribute Summary collapse
- #accepted_types ⇒ Array<Type> readonly
Instance Method Summary collapse
-
#[](i) ⇒ Type
The type at index
i. -
#check(obj) ⇒ Type?
The first type which matched
obj, ornilif none. -
#first ⇒ Type
The first type.
-
#initialize(types) ⇒ TypeConstraint
constructor
A new instance of TypeConstraint.
-
#to_s ⇒ String
A YARD type string describing this set of types.
Constructor Details
#initialize(types) ⇒ TypeConstraint
Returns a new instance of TypeConstraint.
13 14 15 |
# File 'lib/yard_types/types.rb', line 13 def initialize(types) @accepted_types = types end |
Instance Attribute Details
#accepted_types ⇒ Array<Type> (readonly)
10 11 12 |
# File 'lib/yard_types/types.rb', line 10 def accepted_types @accepted_types end |
Instance Method Details
#[](i) ⇒ Type
TODO:
deprecate this; remnant from original TDD’d API.
Returns the type at index i.
20 21 22 |
# File 'lib/yard_types/types.rb', line 20 def [](i) accepted_types[i] end |
#check(obj) ⇒ Type?
Returns The first type which matched obj, or nil if none.
33 34 35 |
# File 'lib/yard_types/types.rb', line 33 def check(obj) accepted_types.find { |t| t.check(obj) } end |
#first ⇒ Type
TODO:
deprecate this; remnant from original TDD’d API.
Returns the first type.
26 27 28 |
# File 'lib/yard_types/types.rb', line 26 def first self[0] end |
#to_s ⇒ String
Returns A YARD type string describing this set of types.
39 40 41 |
# File 'lib/yard_types/types.rb', line 39 def to_s accepted_types.map(&:to_s).join(', ') end |