<commit_before>class Object
  def try(method, *args, &block)
    send(method, *args, &block) if respond_to?(method, true)
  end
end

class Hash
  def prune
    self.each do |key, value|
      value.prune if value.is_a?(Hash)
      delete(key) if value.to_s.empty?
    end
  end
end<commit_msg>Renaming the hash method from prune to cleanse<commit_after>class Object
  def try(method, *args, &block)
    send(method, *args, &block) if respond_to?(method, true)
  end
end

class Hash
  # Recursively removes nil and empty values from a hash and returns a new clean hash.
  # 
  # hash = { 
  #   :name => nil, 
  #   :country => 'US', 
  #   :preferences => {
  #     :quality => nil,
  #     :sites => {
  #       :small => [],
  #       :medium => []
  #     }
  #   } 
  # }
  # hash.cleanse
  # => {:country=>"US"}
  # 
  def cleanse
    self.each do |key, value|
      value.cleanse if value.is_a?(Hash)
      delete(key) if value.to_s.empty?
    end
  end
end
{'fraction_non_alphanumeric': 0.1360332294911734, 'fraction_numerical': 0.0, 'mean_word_length': 2.48014440433213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '3271792', 'n_tokens_mistral': 360, 'n_tokens_neox': 353, 'n_words': 96}