Sha256: 1a55d8b72101c7af72e089094eec723ec28792861f7d391927a4e756bb4138be

Contents?: true

Size: 485 Bytes

Versions: 34

Compression:

Stored size: 485 Bytes

Contents

# Collection of utility methods for the Hash object
class HashUtil
  
  # Returns a hash with the keys converted to symbols
  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
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
cobweb-1.0.10 lib/hash_util.rb
cobweb-1.0.9 lib/hash_util.rb
cobweb-1.0.8 lib/hash_util.rb
cobweb-1.0.6 lib/hash_util.rb
cobweb-1.0.5 lib/hash_util.rb
cobweb-1.0.4 lib/hash_util.rb
cobweb-1.0.3 lib/hash_util.rb
cobweb-1.0.2 lib/hash_util.rb
cobweb-1.0.1 lib/hash_util.rb
cobweb-1.0.0 lib/hash_util.rb
cobweb-0.0.77 lib/hash_util.rb
cobweb-0.0.76 lib/hash_util.rb
cobweb-0.0.75 lib/hash_util.rb
cobweb-0.0.74 lib/hash_util.rb