Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#symbolize_keysObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/core_ext/hash_patch.rb', line 2

def symbolize_keys
  inject({ }) do |options, (key, value)|
    new_key = case key
    when String
      Integer(key) rescue key.to_sym
    end
    
    new_value = case value
    when Hash then value.symbolize_keys
    when String
      Integer(value) rescue value
    else value
    end
    
    options[new_key] = new_value
    options
  end
end

#symbolize_keys!Object



21
22
23
# File 'lib/core_ext/hash_patch.rb', line 21

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