<commit_before>require 'active_support/concern'
require 'pymn/chain_of_responsibility/command_not_handled_error'
require 'pymn/chain_of_responsibility/responsibility_method_undefined_error'

module Pymn
  module ChainOfResponsibility
    extend ActiveSupport::Concern

    module ClassMethods

      def responsibility method, &block
        unless method_defined?(method)
          raise ResponsibilityMethodUndefinedError.new(method)
        end

        command_method = "__command_#{method}".to_sym
        alias_method command_method, method

        self.define_method(method) do |*args|
          if self.instance_eval(&block) 
            return self.send(command_method, *args)
          end

          if @next_handler_in_chain
            return @next_handler_in_chain.send(method, *args)
          end

          raise CommandNotHandledError.new(method)
        end

      end

    end

    def add_handler(next_handler)
      @next_handler_in_chain = next_handler
    end


  end
end<commit_msg>avoiding self.private issues with rubinius<commit_after>require 'active_support/concern'
require 'pymn/chain_of_responsibility/command_not_handled_error'
require 'pymn/chain_of_responsibility/responsibility_method_undefined_error'

module Pymn
  module ChainOfResponsibility
    extend ActiveSupport::Concern

    module ClassMethods

      def responsibility method, &block
        unless method_defined?(method)
          raise ResponsibilityMethodUndefinedError.new(method)
        end

        command_method = "__command_#{method}".to_sym
        alias_method command_method, method

        define_method(method) do |*args|
          if instance_eval(&block) 
            return send(command_method, *args)
          end

          if @next_handler_in_chain
            return @next_handler_in_chain.send(method, *args)
          end

          raise CommandNotHandledError.new(method)
        end

      end

    end

    def add_handler(next_handler)
      @next_handler_in_chain = next_handler
    end


  end
end
{'fraction_non_alphanumeric': 0.059113300492610835, 'fraction_numerical': 0.0, 'mean_word_length': 2.9590643274853803, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4314400', 'n_tokens_mistral': 595, 'n_tokens_neox': 571, 'n_words': 113}