<commit_before>class Hash
  def flatten(joiner=".", &block)
    flat = combine_keys(self, joiner, [], &block).flatten
    Hash[*flat.map {|f| f.to_a}.flatten]
  end
  
private
  def combine_keys(data, joiner=".", prefix=[], &block)
    if data.respond_to?(:keys)
      data.keys.collect do |key|
        combine_keys(data[key], joiner, [prefix, key], &block)
      end.flatten
    else
      return nil if block_given? && !yield(data)
      require 'ruby-debug'
      debugger
      [prefix.flatten.join(joiner) => data]
    end
  end
end<commit_msg>Add logic for ruby-debug gem version<commit_after>class Hash
  def flatten(joiner=".", &block)
    flat = combine_keys(self, joiner, [], &block).flatten
    Hash[*flat.map {|f| f.to_a}.flatten]
  end
  
private
  def combine_keys(data, joiner=".", prefix=[], &block)
    if data.respond_to?(:keys)
      data.keys.collect do |key|
        combine_keys(data[key], joiner, [prefix, key], &block)
      end.flatten
    else
      return nil if block_given? && !yield(data)
      begin
        require 'ruby-debug'
      rescue LoadError
        if RUBY_VERSION.to_f == 1.9
          rdebug_version = "ruby-debug19"
        else
          rdebug_version = "ruby-debug"
        end
        puts "Missing ruby-debug. Install with: gem install #{rdebug_version}"
      end
      [prefix.flatten.join(joiner) => data]
    end
  end
end
{'fraction_non_alphanumeric': 0.13435003631082063, 'fraction_numerical': 0.002904865649963689, 'mean_word_length': 2.704301075268817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5856637', 'n_tokens_mistral': 480, 'n_tokens_neox': 468, 'n_words': 112}