Class: Shaped::Shapes::Any

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

Instance Method Summary collapse

Constructor Details

#initialize(*shape_descriptions) ⇒ Any

Returns a new instance of Any.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/shaped/shapes/any.rb', line 4

def initialize(*shape_descriptions)
  validation_options = shape_descriptions.extract_options!
  if shape_descriptions.size <= 1
    raise(Shaped::InvalidShapeDescription, <<~ERROR.squish)
      A #{self.class} description must be a list of two or more shape descriptions.
    ERROR
  end

  @shapes =
    shape_descriptions.map do |description|
      Shaped::Shape(description, validation_options)
    end
end

Instance Method Details

#matched_by?(object) ⇒ Boolean

Returns:

  • (Boolean)


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

def matched_by?(object)
  @shapes.any? { |shape| shape.matched_by?(object) }
end

#to_sObject



22
23
24
# File 'lib/shaped/shapes/any.rb', line 22

def to_s
  @shapes.map(&:to_s).join(' OR ')
end