Module: Hashie::Extensions::StringifyKeys

Included in:
Hash
Defined in:
lib/hashie/extensions/stringify_keys.rb

Instance Method Summary collapse

Instance Method Details

#stringify_keysObject

Return a new hash with all keys converted to strings.



20
21
22
# File 'lib/hashie/extensions/stringify_keys.rb', line 20

def stringify_keys
  dup.stringify_keys!
end

#stringify_keys!Object

Convert all keys in the hash to strings.

Examples:

test = {:abc => 'def'}
test.stringify_keys!
test # => {'abc' => 'def'}


10
11
12
13
14
15
16
# File 'lib/hashie/extensions/stringify_keys.rb', line 10

def stringify_keys!
  keys.each do |k|
    stringify_keys_recursively!(self[k])
    self[k.to_s] = delete(k)
  end
  self
end