Sha256: 7b76823e984c53d8eda3f5709246c29fea607beb8e0939d98387507aa8060862
Contents?: true
Size: 908 Bytes
Versions: 23
Compression:
Stored size: 908 Bytes
Contents
# :nodoc: module Prmd # Hash helper methods # # @api private module HashHelpers # Attempts to convert all keys in the hash to a Symbol. # This operation is recursive with subhashes # # @param [Hash] hash # @return [Hash] def self.deep_symbolize_keys(hash) deep_transform_keys(hash) do |key| if key.respond_to?(:to_sym) key.to_sym else key end end end # Think of this as hash.keys.map! { |key| }, that actually maps recursively. # # @param [Hash] hash # @return [Hash] # @yield [Object] key def self.deep_transform_keys(hash, &block) result = {} hash.each do |key, value| new_key = yield(key) new_value = value new_value = deep_transform_keys(value, &block) if value.is_a?(Hash) result[new_key] = new_value end result end end end
Version data entries
23 entries across 23 versions & 1 rubygems