<commit_before>module Puppet::Parser::Util
  class Merger
    
    attr_reader :h1, :h2

    def initialize h1, h2
      @h1, @h2 = h1, h2
      raise ArgumentError unless is_hashish?(h1)
      raise ArgumentError unless is_hashish?(h2)
    end
    def compute
      compute_inner h1, h2
    end
    def compute_inner kvs1, kvs2
      # if kvs2 didn't have value, return kvs1
      return kvs1 if kvs2.nil?

      merged = kvs1.map { |k, v| 
        # recurse on those keys that have hashish values
        is_hashish?(v) && is_hashish?(kvs2.fetch(k, nil)) ?
          # recurse
          [k, compute_inner(v, kvs2.fetch(k, nil))] :
          # get the value from kvs2, defaulting to value from kvs1
          [k, kvs2.fetch(k, v)]
      # union merge all items of kvs2
      } | kvs2.reject { |k, v| kvs1.has_key? k }.to_a

      Hash[ merged ]
    end
    def is_hashish? thing
      return false if thing.nil?
      [:each, :fetch, :"has_key?", :reject].all? { |m| thing.respond_to? m }
    end
  end
end<commit_msg>fix namespace collision for Hash object<commit_after>module Puppet::Parser::Util
  class Merger
    
    attr_reader :h1, :h2

    def initialize h1, h2
      @h1, @h2 = h1, h2
      raise ArgumentError unless is_hashish?(h1)
      raise ArgumentError unless is_hashish?(h2)
    end
    def compute
      compute_inner h1, h2
    end
    def compute_inner kvs1, kvs2
      # if kvs2 didn't have value, return kvs1
      return kvs1 if kvs2.nil?

      merged = kvs1.map { |k, v| 
        # recurse on those keys that have hashish values
        is_hashish?(v) && is_hashish?(kvs2.fetch(k, nil)) ?
          # recurse
          [k, compute_inner(v, kvs2.fetch(k, nil))] :
          # get the value from kvs2, defaulting to value from kvs1
          [k, kvs2.fetch(k, v)]
      # union merge all items of kvs2
      } | kvs2.reject { |k, v| kvs1.has_key? k }.to_a

      ::Hash[ merged ]
    end
    def is_hashish? thing
      return false if thing.nil?
      [:each, :fetch, :"has_key?", :reject].all? { |m| thing.respond_to? m }
    end
  end
end
{'fraction_non_alphanumeric': 0.10454985479186835, 'fraction_numerical': 0.026137463697967087, 'mean_word_length': 2.2602523659305995, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5264492', 'n_tokens_mistral': 763, 'n_tokens_neox': 756, 'n_words': 224}