Module: Waves::Ext::Hash

Included in:
Hash
Defined in:
lib/waves/ext/hash.rb

Overview

Utility methods mixed into Hash.

Instance Method Summary collapse

Instance Method Details

#stringify_keysObject

Return a copy of the hash where all keys have been converted to strings.



8
9
10
11
12
13
# File 'lib/waves/ext/hash.rb', line 8

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

#symbolize_keys!Object

Destructively convert all keys to symbols.



16
17
18
19
20
21
22
23
24
# File 'lib/waves/ext/hash.rb', line 16

def symbolize_keys!
  keys.each do |key|
    unless key.is_a?(Symbol)
      self[key.to_sym] = self[key]
      delete(key)
    end
  end
  self
end