Class: DuckTesting::Type::OrderIndependentArray

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*types) ⇒ OrderIndependentArray

Returns a new instance of OrderIndependentArray.



8
9
10
# File 'lib/duck_testing/type/order_independent_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_independent_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_independent_array.rb', line 14

def match?(array)
  return false unless array.is_a?(Array)
  array.all? do |array_element|
    types.any? { |type| type.match?(array_element) }
  end
end

#to_sString

Returns:

  • (String)


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

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