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