<commit_before>class Gimei
  class RetryLimitExceeded < StandardError; end

  class UniqueGenerator
    class << self
      def previous_results
        @previous_results ||= Hash.new { |hash, key| hash[key] = Set.new }
      end

      def define_unique_method(method_name, previous_result_key = method_name)
        define_method method_name do |*args|
          max_retries.times do
            result = Gimei.public_send(method_name, *args)

            next if previous_results[previous_result_key].include?(result.to_s)

            previous_results[previous_result_key] << result.to_s
            return result
          end

          raise RetryLimitExceeded, "Retry limit exceeded for #{method_name}"
        end
      end
    end

    def initialize(max_retries)
      @max_retries = max_retries
    end

    def previous_results
      self.class.previous_results
    end

    def clear(key = nil)
      if key
        previous_results(key.to_sym).clear
      else
        previous_results.clear
      end
    end

    %i[name last first address prefecture city town].each do |method_name|
      define_unique_method(method_name)
    end

    %i[male female kanji hiragana katakana romaji].each do |method_name|
      define_unique_method(method_name, :name)
    end
<commit_msg>define_unique_method add singleton methods instead of instance methods<commit_after>class Gimei
  class RetryLimitExceeded < StandardError; end

  class UniqueGenerator
    class << self
      def previous_results
        @previous_results ||= Hash.new { |hash, key| hash[key] = Set.new }
      end
    end

    def initialize(max_retries)
      @max_retries = max_retries

      %i[name last first address prefecture city town].each do |method_name|
        define_unique_method(method_name)
      end

      %i[male female kanji hiragana katakana romaji].each do |method_name|
        define_unique_method(method_name, :name)
      end
    end

    def previous_results
      self.class.previous_results
    end

    def clear(key = nil)
      if key
        previous_results(key.to_sym).clear
      else
        previous_results.clear
      end
    end

    def define_unique_method(method_name, previous_result_key = method_name)
      define_singleton_method method_name do |*args|
        max_retries.times do
          result = Gimei.public_send(method_name, *args)

          next if previous_results[previous_result_key].include?(result.to_s)

          previous_results[previous_result_key] << result.to_s
          return result
        end

        raise RetryLimitExceeded, "Retry limit exceeded for #{method_name}"
      end
    end

{'fraction_non_alphanumeric': 0.06446719757299962, 'fraction_numerical': 0.0, 'mean_word_length': 2.6537396121883656, 'pattern_counts': {'":': 0, '<': 13, '<?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': '2463283', 'n_tokens_mistral': 800, 'n_tokens_neox': 768, 'n_words': 189}