<commit_before># encoding: utf-8

module Ramom
  module Operation

    class Registry
      include Concord.new(:dressers, :environment, :operation)
      include Lupo.enumerable(:operations)

      def initialize(*args)
        super
        @operations = {}
      end

      def register(name, options, &block)
        dresser = dressers[options.fetch(:dresser)]

        op = operation.new(name, environment, dresser)
        (class << op; self end).class_eval {
          define_method(:call, &block)
        }

        @operations[name] = op
      end

      def fetch(*args, &block)
        @operations.fetch(*args, &block)
      end
    end # Registry
  end # Operation
end # Ramom<commit_msg>Explain the use of object singleton methods<commit_after># encoding: utf-8

module Ramom
  module Operation

    class Registry
      include Concord.new(:dressers, :environment, :operation)
      include Lupo.enumerable(:operations)

      def initialize(*args)
        super
        @operations = {}
      end

      def register(name, options, &block)
        dresser = dressers[options.fetch(:dresser)]
        op      = operation.new(name, environment, dresser)

        # We basically use the op instance as the context
        # to evaluate the function given as &block. This
        # is probably a bit unusual for typical OO, it is
        # however perfectly valid ruby, and simply another
        # way of doing (prototype oriented) functional OOP

        (class << op; self end).class_eval {
          define_method(:call, &block)
        }

        @operations[name] = op
      end

      def fetch(*args, &block)
        @operations.fetch(*args, &block)
      end
    end # Registry
  end # Operation
end # Ramom
{'fraction_non_alphanumeric': 0.09322524609148813, 'fraction_numerical': 0.0011580775911986102, 'mean_word_length': 2.335907335907336, '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': '2863059', 'n_tokens_mistral': 497, 'n_tokens_neox': 468, 'n_words': 148}