Class: Bake::Type::Tuple

Inherits:
Object
  • Object
show all
Includes:
Type
Defined in:
lib/bake/type/tuple.rb

Instance Method Summary collapse

Methods included from Type

#|

Constructor Details

#initialize(item_types) ⇒ Tuple

Returns a new instance of Tuple.



13
14
15
# File 'lib/bake/type/tuple.rb', line 13

def initialize(item_types)
  @item_types = item_types
end

Instance Method Details

#composite?Boolean

Returns:



17
18
19
# File 'lib/bake/type/tuple.rb', line 17

def composite?
  true
end

#parse(input) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/bake/type/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_sObject



32
33
34
# File 'lib/bake/type/tuple.rb', line 32

def to_s
  "a Tuple of (#{@item_types.join(', ')})"
end