Method: Hash#deep_stringify

Defined in:
lib/core_ext/hash.rb

#deep_stringifyObject

Returns a new hash just like this one, but with all the symbol keys expressed as strings. Also applies to hashes within self. Based on an implementation within Rails 2.x, thanks Rails!



18
19
20
21
22
23
24
25
# File 'lib/core_ext/hash.rb', line 18

def deep_stringify
  target = dup
  target.inject({}) do |memo, (key, value)|
    value = value.deep_stringify if value.is_a?(Hash)
    memo[(key.to_s rescue key) || key] = value
    memo
  end
end