Module: Hashie::Extensions::StringifyKeys

Defined in:
lib/hashie/extensions/key_conversion.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) stringify_keys

Return a new hash with all keys converted to strings.



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

def stringify_keys
  dup.stringify_keys!
end

- (Object) stringify_keys!

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/key_conversion.rb', line 10

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