<commit_before># BioCatalogue: lib/object.rb

# From: http://ozmm.org/posts/try.html

class Object
  #instead of a and a.b and a.b.c and a.b.c.d?
  #try_block {a.b.c.d?}
  #in addition for being useful for nil's, works for any object that doesn't provide the required method
  #so instead of a.respond_to? :b? and a.b? try_block { a.b? }
  def try_block
    yield
  rescue NoMethodError, NameError
    nil
  end

end

Module.module_eval do
  def class_alias_method_chain name, feature
    singleton_class.instance_eval do
      alias_method_chain name, feature
    end
  end
end
<commit_msg>fix nil.id exception on try_block<commit_after># BioCatalogue: lib/object.rb

# From: http://ozmm.org/posts/try.html

class Object
  #instead of a and a.b and a.b.c and a.b.c.d?
  #try_block {a.b.c.d?}
  #in addition for being useful for nil's, works for any object that doesn't provide the required method
  #so instead of a.respond_to? :b? and a.b? try_block { a.b? }
  def try_block
    yield
    rescue NoMethodError, NameError
      nil
    rescue RuntimeError => e
     if e.message.to_s == "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id"
        nil
     else
        raise
     end
  end

end

Module.module_eval do
  def class_alias_method_chain name, feature
    singleton_class.instance_eval do
      alias_method_chain name, feature
    end
  end
end

{'fraction_non_alphanumeric': 0.08167613636363637, 'fraction_numerical': 0.0007102272727272727, 'mean_word_length': 3.002840909090909, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2585954', 'n_tokens_mistral': 493, 'n_tokens_neox': 488, 'n_words': 166}