Class: Hash

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

Overview

:title: Class: Hash

Instance Method Summary collapse

Instance Method Details

#recursive_symbolize_keysObject

Return a new instance of Hash which represents the same data as self but with all keys - including those of sub-hashes - symbolized



11
12
13
14
15
16
17
# File 'lib/core-extensions/hash.rb', line 11

def recursive_symbolize_keys
  new_hash = {}
  self.each_pair do |k,v|
    new_hash[k.to_sym] = value_or_symbolize_value(v)
  end
  new_hash
end

#recursive_symbolize_keys!Object

Modify self in place, transforming all keys - including those of sub-hashes - in to symbols



22
23
24
25
26
27
28
29
# File 'lib/core-extensions/hash.rb', line 22

def recursive_symbolize_keys!
  items = {}
  self.each_pair do |k,v|
    value = delete(k)
    items[k] = value_or_symbolize_value(value)
  end
  items
end