module NCCO::Utils
Public Class Methods
deep_transform_keys(hash) { |key| ... }
click to toggle source
Transforms the keys of a Hash with the provided block recursively, walking through nested hashes
@param hash [Hash] the hash to transform @yieldparam the key to transform @return [Hash] the transformed hash, with the block recursively applied to its keys
# File lib/ncco/utils.rb, line 11 def self.deep_transform_keys(hash, &block) result = {} hash.each do |key, value| result[yield(key)] = if value.is_a?(Hash) deep_transform_keys(value, &block) else value end end result end
deep_transform_keys_to_symbols(hash)
click to toggle source
Transforms the keys of Hash into symbols recursively, walking through nested hashes
@param hash [Hash] the hash to transform
# File lib/ncco/utils.rb, line 28 def self.deep_transform_keys_to_symbols(hash) deep_transform_keys(hash, &:to_sym) end