Class: Hash

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

Overview

Copied from ActiveSupport, included if we don’t already have it

Instance Method Summary collapse

Instance Method Details

#stringify_keysObject

Return a new hash with all keys converted to strings.



15
16
17
18
19
20
# File 'lib/hash-ext.rb', line 15

def stringify_keys
  inject({}) do |options, (key, value)|
    options[(key.to_s rescue key) || key] = value
    options
  end
end

#stringify_keys!Object



21
22
23
# File 'lib/hash-ext.rb', line 21

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

#symbolize_keysObject

Return a new hash with all keys converted to symbols.



5
6
7
8
9
10
# File 'lib/hash-ext.rb', line 5

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

#symbolize_keys!Object



11
12
13
# File 'lib/hash-ext.rb', line 11

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