Module: Hashie::Extensions::SymbolizeKeys

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

Instance Method Summary collapse

Instance Method Details

#symbolize_keysObject

Return a new hash with all keys converted to symbols.


61
62
63
# File 'lib/hashie/extensions/key_conversion.rb', line 61

def symbolize_keys
  dup.symbolize_keys!
end

#symbolize_keys!Object

Convert all keys in the hash to symbols.

Examples:

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

51
52
53
54
55
56
57
# File 'lib/hashie/extensions/key_conversion.rb', line 51

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