Class: ActiveAttrExtended::Typecasting::ArrayTypecaster
- Inherits:
-
Object
- Object
- ActiveAttrExtended::Typecasting::ArrayTypecaster
- Defined in:
- lib/active_attr_extended/typecasting/array_typecaster.rb
Overview
Typecasts an Object to an Array
Instance Method Summary collapse
-
#call(value) ⇒ Array?
Typecasts an Object to an Array.
Instance Method Details
#call(value) ⇒ Array?
Typecasts an Object to an Array
Will typecast any Object except nil to an Array, first by attempting to call ‘#to_a`, then by wrapping `value` in an Array (`[value]`).
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/active_attr_extended/typecasting/array_typecaster.rb', line 25 def call(value) #treat incoming strings as serialized JSON value = JSON::parse(value) if value.is_a? String if value.nil? nil elsif value.respond_to? :to_a value.to_a else [value] end end |