Class: ActiveAttrExtended::Typecasting::HashTypecaster
- Inherits:
-
Object
- Object
- ActiveAttrExtended::Typecasting::HashTypecaster
- Defined in:
- lib/active_attr_extended/typecasting/hash_typecaster.rb
Overview
Typecasts an Object to a Hash
Instance Method Summary collapse
-
#call(value) ⇒ Hash?
Typecasts an Object to a Hash.
Instance Method Details
#call(value) ⇒ Hash?
Typecasts an Object to a Hash
Will typecast JSON or Hashes into a Hash
26 27 28 29 30 |
# 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 |