Method: Hanami::Utils::Hash.deep_serialize
- Defined in:
- lib/hanami/utils/hash.rb
.deep_serialize(input) ⇒ ::Hash
Deep serializes given object into a Hash
Please note that the returning Hash will use symbols as keys.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/hanami/utils/hash.rb', line 170 def self.deep_serialize(input) input.to_hash.each_with_object({}) do |(key, value), output| output[key.to_sym] = case value when ->(h) { h.respond_to?(:to_hash) } deep_serialize(value) when Array value.map do |item| item.respond_to?(:to_hash) ? deep_serialize(item) : item end else value end end end |