Method: Hash#deep_symbolize

Defined in:
lib/core_ext/hash.rb

#deep_symbolizeObject

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



6
7
8
9
10
11
12
13
# File 'lib/core_ext/hash.rb', line 6

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