<commit_before>module Memoist2

  def self.memoized_ivar_for(symbol)
    "@_memoized_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym
  end

  module ClassMethods

    def memoize(*method_names)
      method_names.each do |method_name|
        memoized_ivar = Memoist2.memoized_ivar_for(method_name)
        memoized_module = Module.new do
          module_eval <<-EVAL
            def #{method_name}
              unless #{memoized_ivar}
                #{memoized_ivar} = [super]
              end
              #{memoized_ivar}[0]
            end
          EVAL
        end
        prepend memoized_module
      end
    end

    def memoize_class_method(*method_names)
      singleton_class.class_eval do
        include Memoist2 unless ancestors.include?(Memoist2)
        memoize *method_names
      end
    end

  end

  def self.included(klass)
    klass.extend(ClassMethods)
  end
end<commit_msg>add a meaningful inspect to the magic modules<commit_after>module Memoist2

  def self.memoized_ivar_for(symbol)
    "@_memoized_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym
  end

  module ClassMethods

    def memoize(*method_names)
      method_names.each do |method_name|
        memoized_ivar = Memoist2.memoized_ivar_for(method_name)
        memoized_module = Module.new do
          module_eval <<-EVAL
            def #{method_name}
              unless #{memoized_ivar}
                #{memoized_ivar} = [super]
              end
              #{memoized_ivar}[0]
            end

            def self.to_s
              "Memoist2::MemoizedMethod(#{method_name})"
            end
            def self.inspect; to_s; end
          EVAL
        end
        prepend memoized_module
      end
    end

    def memoize_class_method(*method_names)
      singleton_class.class_eval do
        include Memoist2 unless ancestors.include?(Memoist2)
        memoize *method_names
      end
    end
  end

  def self.included(klass)
    klass.extend(ClassMethods)
  end
end
{'fraction_non_alphanumeric': 0.08801591248135256, 'fraction_numerical': 0.005469915464942815, 'mean_word_length': 2.076452599388379, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5167572', 'n_tokens_mistral': 665, 'n_tokens_neox': 668, 'n_words': 124}