Class: Shaped::Shapes::Array
- Inherits:
-
Shaped::Shape
- Object
- Shaped::Shape
- Shaped::Shapes::Array
- Defined in:
- lib/shaped/shapes/array.rb
Instance Method Summary collapse
-
#initialize(shape_description) ⇒ Array
constructor
A new instance of Array.
- #matched_by?(array) ⇒ Boolean
- #to_s ⇒ Object
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
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_s ⇒ Object
18 19 20 |
# File 'lib/shaped/shapes/array.rb', line 18 def to_s "[#{@element_test}]" end |