<commit_before>module Foreplay
  class Utility
    # Returns a new hash with +hash+ and +other_hash+ merged recursively, including arrays.
    #
    #   h1 = { x: { y: [4,5,6] }, z: [7,8,9] }
    #   h2 = { x: { y: [7,8,9] }, z: 'xyz' }
    #   h1.supermerge(h2)
    #   #=> {:x=>{:y=>[4, 5, 6, 7, 8, 9]}, :z=>[7, 8, 9, "xyz"]}
    def self.supermerge(hash, other_hash)
      fail 'supermerge only works if you pass two hashes' unless hash.is_a?(Hash) && other_hash.is_a?(Hash)

      new_hash = hash.deep_dup.with_indifferent_access

      other_hash.each_pair do |k, v|
        tv = new_hash[k]

        if tv.is_a?(Hash) && v.is_a?(Hash)
          new_hash[k] = Foreplay::Utility.supermerge(tv, v)
        elsif tv.is_a?(Array) || v.is_a?(Array)
          new_hash[k] = Array.wrap(tv) + Array.wrap(v)
        else
          new_hash[k] = v
        end
      end

      new_hash
    end
  end
end<commit_msg>Better supermerge message<commit_after>module Foreplay
  class Utility
    # Returns a new hash with +hash+ and +other_hash+ merged recursively, including arrays.
    #
    #   h1 = { x: { y: [4,5,6] }, z: [7,8,9] }
    #   h2 = { x: { y: [7,8,9] }, z: 'xyz' }
    #   h1.supermerge(h2)
    #   #=> {:x=>{:y=>[4, 5, 6, 7, 8, 9]}, :z=>[7, 8, 9, "xyz"]}
    def self.supermerge(hash, other_hash)
      fail 'supermerge only works if you pass two hashes. '\
        'You passed a {hash.class} and a {other_hash.class}.' unless hash.is_a?(Hash) && other_hash.is_a?(Hash)

      new_hash = hash.deep_dup.with_indifferent_access

      other_hash.each_pair do |k, v|
        tv = new_hash[k]

        if tv.is_a?(Hash) && v.is_a?(Hash)
          new_hash[k] = Foreplay::Utility.supermerge(tv, v)
        elsif tv.is_a?(Array) || v.is_a?(Array)
          new_hash[k] = Array.wrap(tv) + Array.wrap(v)
        else
          new_hash[k] = v
        end
      end

      new_hash
    end
  end
end
{'fraction_non_alphanumeric': 0.1628887717448603, 'fraction_numerical': 0.02319451765946231, 'mean_word_length': 2.353356890459364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '735787', 'n_tokens_mistral': 781, 'n_tokens_neox': 763, 'n_words': 174}