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
The list of types that will satisfy this constraint.
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.
26 27 28 |
# File 'lib/yard_types/types.rb', line 26 def initialize(types) @accepted_types = types end |
Instance Attribute Details
#accepted_types ⇒ Array<Type> (readonly)
Returns the list of types that will satisfy this constraint.
23 24 25 |
# File 'lib/yard_types/types.rb', line 23 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.
33 34 35 |
# File 'lib/yard_types/types.rb', line 33 def [](i) accepted_types[i] end |
#check(obj) ⇒ Type?
Returns the first type which matched obj,
or nil if none.
46 47 48 |
# File 'lib/yard_types/types.rb', line 46 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.
39 40 41 |
# File 'lib/yard_types/types.rb', line 39 def first self[0] end |
#to_s ⇒ String
Returns a YARD type string describing this set of types.
52 53 54 |
# File 'lib/yard_types/types.rb', line 52 def to_s accepted_types.map(&:to_s).join(', ') end |