Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/hash.rb

Overview

Extensions to the core Hash class.

Instance Method Summary collapse

Instance Method Details

#symbolize_keysObject

Turn all string keys into symbols. Returns the modified hash.



4
5
6
7
8
9
# File 'lib/core_ext/hash.rb', line 4

def symbolize_keys
  inject({}) do |options, (key, value)|
    options[key.to_sym || key] = value
    options
  end
end

#symbolize_keys!Object

Destructive version of symbolize_keys.



12
13
14
# File 'lib/core_ext/hash.rb', line 12

def symbolize_keys!
  self.replace(self.symbolize_keys)
end