<commit_before>module Warp
  class Instrument
    class << self
      def for(klass, method)
        @@registry ||= {}
        @@registry[klass] ||= {}
        @@registry[klass][method] || new(klass, method)
      end

      private

      def register(instrument)
        @@registry ||= {}
        @@registry[instrument.klass] ||= {}
        @@registry[instrument.klass][instrument.method] = instrument        
      end
    end

    attr_accessor :klass, :method, :hook, :enabled, :calls

    def initialize(klass, method)
      self.klass = klass
      self.method = method
      self.enabled = false
      self.calls = []
      setup_hook

      self.class.send(:register, self)
    end

    def reset
      self.calls = []
    end

    def run
      enable
      yield
      disable
    end

    def enabled?
      enabled
    end

    def log(args)
      calls << args
    end

    private

    def enable
      self.enabled = true
    end

    def disable
      self.enabled = false
    end

    def setup_hook
      if Module.method_defined?(:prepend)
        self.hook = Module.new

        hook.send(:define_method, method) do |*args|
          if Warp::Instrument.for(self.class, __method__).enabled?
            Warp::Instrument.for(self.class, __method__).log(args)
          end

          super(*args)
        end

        klass.prepend(hook)
      else
        original_method = klass.instance_method(method)

        klass.send(:define_method, method) do |*args|
          if Warp::Instrument.for(self.class, __method__).enabled?
            Warp::Instrument.for(self.class, __method__).log(args)
          end

          original_method.bind(self).call(*args)
        end
      end<commit_msg>Removed instance variable for instrument hook.<commit_after>module Warp
  class Instrument
    class << self
      def for(klass, method)
        @@registry ||= {}
        @@registry[klass] ||= {}
        @@registry[klass][method] || new(klass, method)
      end

      private

      def register(instrument)
        @@registry ||= {}
        @@registry[instrument.klass] ||= {}
        @@registry[instrument.klass][instrument.method] = instrument        
      end
    end

    attr_accessor :klass, :method, :enabled, :calls

    def initialize(klass, method)
      self.klass = klass
      self.method = method
      self.enabled = false
      self.calls = []
      setup_hook

      self.class.send(:register, self)
    end

    def reset
      self.calls = []
    end

    def run
      enable
      yield
      disable
    end

    def enabled?
      enabled
    end

    def log(args)
      calls << args
    end

    private

    def enable
      self.enabled = true
    end

    def disable
      self.enabled = false
    end

    def setup_hook
      if Module.method_defined?(:prepend)
        hook = Module.new

        hook.send(:define_method, method) do |*args|
          if Warp::Instrument.for(self.class, __method__).enabled?
            Warp::Instrument.for(self.class, __method__).log(args)
          end

          super(*args)
        end

        klass.prepend(hook)
      else
        original_method = klass.instance_method(method)

        klass.send(:define_method, method) do |*args|
          if Warp::Instrument.for(self.class, __method__).enabled?
            Warp::Instrument.for(self.class, __method__).log(args)
          end

          original_method.bind(self).call(*args)
        end
      end
{'fraction_non_alphanumeric': 0.1057217542840546, 'fraction_numerical': 0.0, 'mean_word_length': 1.916172734970364, 'pattern_counts': {'":': 0, '<': 11, '<?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': '2935042', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1021, 'n_words': 221}