class ActiveAttrExtended::Typecasting::HashTypecaster
Typecasts an Object to a Hash
@example Usage
HashTypecaster.new.call(1) # => [1]
@since 0.6.0
Public Instance Methods
call(value)
click to toggle source
Typecasts an Object to a Hash
Will typecast JSON or Hashes into a Hash
@example Usage
HashTypecaster.new.call(nil) # => {} HashTypecaster.new.call({:x => :y}) # => {:x => :y} HashTypecaster.new.call({:x => :y}.to_json) # => {:x => :y}
@param [Object] value The object to typecast
@return [Hash, nil] The result of typecasting
@since 0.6.0
# File lib/active_attr_extended/typecasting/hash_typecaster.rb, line 26 def call(value) #treat incoming strings as serialized JSON value = JSON::parse(value) if value.is_a? String value.is_a?(Hash) ? value : {} end