Class: HashUtil

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

Overview

Collection of utility methods for the Hash object

Class Method Summary collapse

Class Method Details

.deep_symbolize_keys(hash) ⇒ Object

Returns a hash with the keys converted to symbols



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/hash_util.rb', line 5

def self.deep_symbolize_keys(hash)
  raise "Cannot symbolize keys for a nil object" if hash.nil?
  hash.keys.each do |key|
    value = hash[key]
    hash.delete(key)
    hash[key.to_sym] = value
    if hash[key.to_sym].instance_of? Hash
      hash[key.to_sym] = HashUtil.deep_symbolize_keys(hash[key.to_sym])
    end
  end
  hash
end