Class: ValueSemantics::ArrayOf

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

Overview

Validator that matches arrays if each element matches a given subvalidator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element_validator) ⇒ ArrayOf

Returns a new instance of ArrayOf.



348
349
350
351
# File 'lib/value_semantics.rb', line 348

def initialize(element_validator)
  @element_validator = element_validator
  freeze
end

Instance Attribute Details

#element_validatorObject (readonly)

Returns the value of attribute element_validator.



346
347
348
# File 'lib/value_semantics.rb', line 346

def element_validator
  @element_validator
end

Instance Method Details

#===(value) ⇒ Boolean

Returns:

  • (Boolean)


354
355
356
# File 'lib/value_semantics.rb', line 354

def ===(value)
  Array === value && value.all? { |element| element_validator === element }
end