Module: Hashie::Extensions::SymbolizeKeys

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) symbolize_keys

Return a new hash with all keys converted to symbols.



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

def symbolize_keys
  dup.symbolize_keys!
end

- (Object) symbolize_keys!

Convert all keys in the hash to symbols.

Examples:

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


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

def symbolize_keys!
  keys.each do |k|
    symbolize_keys_recursively!(self[k])
    self[k.to_sym] = delete(k)
  end
  self
end