Sha256: 3c308b1007adffb91eaa81ef37ae1ba8a788daf2bcc5608d84453bb97f1b15b0
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true module Contrast module Utils # Module to hold various hash utils methods module HashUtils class << self # Merges two hashes, first hash will preserve it's values and will only add unique values. # # @param hsh [Hash] # @param other_hsh [Hash] def deep_merge hsh, other_hsh hsh.merge(other_hsh) do |_key, old_value, new_value| old_value.is_a?(Hash) || new_value.is_a?(Hash) ? deep_merge(old_value, new_value) : old_value end end # Deep symbolizes all keys # @param value [Hash] # @return [Hash] def deep_symbolize_all_keys value new_hash = {} value.each { |key, v| new_hash[key.to_sym] = map_value(v) } new_hash end private def map_value value case value when Hash deep_symbolize_all_keys(value) when Array value.map { |v| map_value(v) } else value end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
contrast-agent-7.1.0 | lib/contrast/utils/hash_utils.rb |