Class: Bake::Types::Tuple
- Inherits:
-
Object
- Object
- Bake::Types::Tuple
- Includes:
- Type
- Defined in:
- lib/bake/types/tuple.rb
Instance Method Summary collapse
- #composite? ⇒ Boolean
-
#initialize(item_types) ⇒ Tuple
constructor
A new instance of Tuple.
- #parse(input) ⇒ Object
- #to_s ⇒ Object
Methods included from Type
Constructor Details
#initialize(item_types) ⇒ Tuple
Returns a new instance of Tuple.
13 14 15 |
# File 'lib/bake/types/tuple.rb', line 13 def initialize(item_types) @item_types = item_types end |
Instance Method Details
#parse(input) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bake/types/tuple.rb', line 21 def parse(input) case input when ::String return input.split(',').map{|value| @item_type.parse(value)} when ::Array return input.map{|value| @item_type.parse(value)} else raise ArgumentError, "Cannot coerce #{input.inspect} into tuple!" end end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/bake/types/tuple.rb', line 32 def to_s "a Tuple of (#{@item_types.join(', ')})" end |