Sha256: 7f1c37fe9c19ed8600b80ef07e1648911e1249965f90caff99230215a25ee773
Contents?: true
Size: 651 Bytes
Versions: 17
Compression:
Stored size: 651 Bytes
Contents
# frozen_string_literal: true Hash.class_eval do # Do a deep merge, but don't override the key-value pairs on the left. # # @param other_hash [Hash] # # @return [Hash] # def left_deep_merge!(other_hash, &block) merge!(other_hash) do |key, this_val, other_val| if this_val.is_a?(Hash) && other_hash.is_a?(Hash) this_val.left_deep_merge(other_val, &block) elsif block_given? yield(key, this_val, other_val) else this_val.presence || other_val end end end # @see #left_deep_merge! def left_deep_merge(other_hash, &block) dup.left_deep_merge!(other_hash, &block) end end
Version data entries
17 entries across 17 versions & 1 rubygems