Sha256: d4724e3046c45d20acbd0dd23653a14e98a3ce21e8fd7d558096eb5bbf07b317

Contents?: true

Size: 755 Bytes

Versions: 12

Compression:

Stored size: 755 Bytes

Contents

module Hashie
  module Extensions
    module DeepMerge
      # Returns a new hash with +self+ and +other_hash+ merged recursively.
      def deep_merge(other_hash)
        dup.deep_merge!(other_hash)
      end

      # Returns a new hash with +self+ and +other_hash+ merged recursively.
      # Modifies the receiver in place.
      def deep_merge!(other_hash)
        _recursive_merge(self, other_hash)
        self
      end

      private

      def _recursive_merge(hash, other_hash)
        if other_hash.is_a?(::Hash) && hash.is_a?(::Hash)
          other_hash.each do |k, v|
            hash[k] = hash.key?(k) ? _recursive_merge(hash[k], v) : v
          end
          hash
        else
          other_hash
        end
      end
    end
  end
end

Version data entries

12 entries across 11 versions & 3 rubygems

Version Path
hashie-3.3.2 lib/hashie/extensions/deep_merge.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/hashie-3.3.1/lib/hashie/extensions/deep_merge.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/hashie-3.3.1/lib/hashie/extensions/deep_merge.rb
hashie-3.3.1 lib/hashie/extensions/deep_merge.rb
hashie-3.2.0 lib/hashie/extensions/deep_merge.rb
hashie-3.1.0 lib/hashie/extensions/deep_merge.rb
whos_dated_who-0.1.0 vendor/bundle/gems/hashie-3.0.0/lib/hashie/extensions/deep_merge.rb
whos_dated_who-0.0.1 vendor/bundle/gems/hashie-3.0.0/lib/hashie/extensions/deep_merge.rb
hashie-2.1.2 lib/hashie/extensions/deep_merge.rb
hashie-3.0.0 lib/hashie/extensions/deep_merge.rb
hashie-2.1.1 lib/hashie/extensions/deep_merge.rb
hashie-2.1.0 lib/hashie/extensions/deep_merge.rb