Class: DuckTesting::Type::OrderDependentArray
- Defined in:
- lib/duck_testing/type/order_dependent_array.rb
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
-
#initialize(*types) ⇒ OrderDependentArray
constructor
A new instance of OrderDependentArray.
- #match?(array) ⇒ Boolean
- #to_s ⇒ String
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
#types ⇒ Object (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
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_s ⇒ 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 |