Module: Payments::HashExt

Included in:
Hash
Defined in:
lib/payments_pl/hash_ext.rb

Instance Method Summary collapse

Instance Method Details

#stringify_keysObject



3
4
5
6
7
8
# File 'lib/payments_pl/hash_ext.rb', line 3

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

#stringify_keys!Object



10
11
12
13
14
15
# File 'lib/payments_pl/hash_ext.rb', line 10

def stringify_keys!
  keys.each do |key|
    self[key.to_s] = delete(key)
  end
  self
end

#symbolize_keysObject



17
18
19
20
21
22
# File 'lib/payments_pl/hash_ext.rb', line 17

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

#symbolize_keys!Object



24
25
26
# File 'lib/payments_pl/hash_ext.rb', line 24

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