Class: Strict::Coercers::Array
- Inherits:
-
Object
- Object
- Strict::Coercers::Array
- Defined in:
- lib/strict/coercers/array.rb
Instance Attribute Summary collapse
-
#element_coercer ⇒ Object
readonly
Returns the value of attribute element_coercer.
Instance Method Summary collapse
- #call(value) ⇒ Object
-
#initialize(element_coercer = nil) ⇒ Array
constructor
A new instance of Array.
Constructor Details
#initialize(element_coercer = nil) ⇒ Array
Returns a new instance of Array.
8 9 10 |
# File 'lib/strict/coercers/array.rb', line 8 def initialize(element_coercer = nil) @element_coercer = element_coercer end |
Instance Attribute Details
#element_coercer ⇒ Object (readonly)
Returns the value of attribute element_coercer.
6 7 8 |
# File 'lib/strict/coercers/array.rb', line 6 def element_coercer @element_coercer end |
Instance Method Details
#call(value) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/strict/coercers/array.rb', line 12 def call(value) return value if value.nil? || !value.respond_to?(:to_a) array = value.to_a return array unless element_coercer array.map { |element| element_coercer.call(element) } end |