class ActiveAttrExtended::Typecasting::ArrayTypecaster
Typecasts an Object to an Array
@example Usage
ArrayTypecaster.new.call(1) # => [1]
@since 0.6.0
Public Instance Methods
call(value)
click to toggle source
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]`).
@example Usage
ArrayTypecaster.new.call(1) # => [1]
@param [Object] value The object to typecast
@return [Array, nil] The result of typecasting
@since 0.6.0
# 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