Sha256: 97427a0fe527ed131b56a6ee017eb090b57086f8f0679cc75df929141c1198ce

Contents?: true

Size: 830 Bytes

Versions: 24

Compression:

Stored size: 830 Bytes

Contents

module TablePrint
  module HashExtensions
    module ConstructiveMerge
      def constructive_merge(hash)
        target = dup

        hash.keys.each do |key|
          if hash[key].is_a? Hash and self[key].is_a? Hash
            target[key].extend ConstructiveMerge
            target[key] = target[key].constructive_merge(hash[key])
            next
          end

          target[key] = hash[key]
        end

        target
      end

      def constructive_merge!(hash)
        target = self

        hash.keys.each do |key|
          if hash[key].is_a? Hash and self[key].is_a? Hash
            target[key].extend ConstructiveMerge
            target[key] = target[key].constructive_merge(hash[key])
            next
          end

          target[key] = hash[key]
        end

        target
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
table_print-1.5.7 lib/table_print/hash_extensions.rb
table_print-1.5.6 lib/table_print/hash_extensions.rb
table_print-1.5.5 lib/table_print/hash_extensions.rb
table_print-1.5.4 lib/table_print/hash_extensions.rb
table_print-1.5.3 lib/table_print/hash_extensions.rb
table_print-1.5.2 lib/table_print/hash_extensions.rb
table_print-1.5.1 lib/table_print/hash_extensions.rb
table_print-1.5.0 lib/table_print/hash_extensions.rb
table_print-1.4.1 lib/table_print/hash_extensions.rb
table_print-1.4.0 lib/table_print/hash_extensions.rb
table_print-1.3.3 lib/table_print/hash_extensions.rb
table_print-1.3.2 lib/table_print/hash_extensions.rb
table_print-1.3.1 lib/table_print/hash_extensions.rb
table_print-1.3.0 lib/table_print/hash_extensions.rb
table_print-1.2.0 lib/table_print/hash_extensions.rb
table_print-1.1.5 lib/table_print/hash_extensions.rb
table_print-1.1.4 lib/table_print/hash_extensions.rb
table_print-1.1.3 lib/table_print/hash_extensions.rb
table_print-1.1.2 lib/table_print/hash_extensions.rb
table_print-1.1.1 lib/table_print/hash_extensions.rb