Class: Shaped::Shapes::Array

Inherits:
Shaped::Shape show all
Defined in:
lib/shaped/shapes/array.rb

Instance Method Summary collapse

Constructor Details

#initialize(shape_description) ⇒ Array

Returns a new instance of Array.



4
5
6
7
8
9
10
# File 'lib/shaped/shapes/array.rb', line 4

def initialize(shape_description)
  if !shape_description.is_a?(Array)
    raise(Shaped::InvalidShapeDescription, "A #{self.class} description must be an array.")
  end

  @element_test = Shaped::Shape(*shape_description)
end

Instance Method Details

#matched_by?(array) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/shaped/shapes/array.rb', line 12

def matched_by?(array)
  return false if !array.is_a?(Array)

  array.all? { |element| @element_test.matched_by?(element) }
end

#to_sObject



18
19
20
# File 'lib/shaped/shapes/array.rb', line 18

def to_s
  "[#{@element_test}]"
end