Class: DuckTesting::Type::OrderDependentArray

Inherits:
Base
  • Object
show all
Defined in:
lib/duck_testing/type/order_dependent_array.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*types) ⇒ OrderDependentArray

Returns a new instance of OrderDependentArray.



8
9
10
# File 'lib/duck_testing/type/order_dependent_array.rb', line 8

def initialize(*types)
  @types = types
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



6
7
8
# File 'lib/duck_testing/type/order_dependent_array.rb', line 6

def types
  @types
end

Instance Method Details

#match?(array) ⇒ Boolean

Parameters:

  • array (Object)

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/duck_testing/type/order_dependent_array.rb', line 14

def match?(array)
  return false unless array.is_a?(Array) && array.size == types.size
  array.zip(types).all? do |array_element, type|
    type.match?(array_element)
  end
end

#to_sString

Returns:

  • (String)


22
23
24
# File 'lib/duck_testing/type/order_dependent_array.rb', line 22

def to_s
  "Array<(#{types.map(&:to_s).join(', ')})>"
end