Class: ValueSemantics::ArrayCoercer
- Inherits:
-
Object
- Object
- ValueSemantics::ArrayCoercer
- Defined in:
- lib/value_semantics/array_coercer.rb
Instance Attribute Summary collapse
-
#element_coercer ⇒ Object
readonly
Returns the value of attribute element_coercer.
Instance Method Summary collapse
- #call(obj) ⇒ Object
-
#initialize(element_coercer = nil) ⇒ ArrayCoercer
constructor
A new instance of ArrayCoercer.
Constructor Details
#initialize(element_coercer = nil) ⇒ ArrayCoercer
Returns a new instance of ArrayCoercer.
5 6 7 8 |
# File 'lib/value_semantics/array_coercer.rb', line 5 def initialize(element_coercer = nil) @element_coercer = element_coercer freeze end |
Instance Attribute Details
#element_coercer ⇒ Object (readonly)
Returns the value of attribute element_coercer.
3 4 5 |
# File 'lib/value_semantics/array_coercer.rb', line 3 def element_coercer @element_coercer end |
Instance Method Details
#call(obj) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/value_semantics/array_coercer.rb', line 10 def call(obj) if obj.respond_to?(:to_a) array = obj.to_a if element_coercer array.map { |element| element_coercer.call(element) } else array end else obj end end |