Class: ValueSemantics::Either

Inherits:
Object
  • Object
show all
Defined in:
lib/value_semantics/either.rb

Overview

Validator that matches if any of the given subvalidators matches

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subvalidators) ⇒ Either

Returns a new instance of Either.



8
9
10
11
# File 'lib/value_semantics/either.rb', line 8

def initialize(subvalidators)
  @subvalidators = subvalidators
  freeze
end

Instance Attribute Details

#subvalidatorsObject (readonly)

Returns the value of attribute subvalidators.



6
7
8
# File 'lib/value_semantics/either.rb', line 6

def subvalidators
  @subvalidators
end

Instance Method Details

#===(value) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/value_semantics/either.rb', line 14

def ===(value)
  subvalidators.any? { |sv| sv === value }
end