<commit_before># encoding: utf-8

require 'backports'

# Module to allow class and methods to be abstract
module AbstractType

  # Hook called when module is included
  #
  # @param [Module] descendant
  #   the module or class including AbstractType
  #
  # @return [undefined]
  #
  # @api private
  def self.included(descendant)
    super
    descendant.extend(ClassMethods)
  end

  private_class_method :included

  module ClassMethods

    # Instantiate a new object
    #
    # Ensures that the instance cannot be of the abstract type
    # and must be a descendant.
    #
    # @example
    #   object = AbstractType.new
    #
    # @return [Object]
    #
    # @api public
    def new(*)
      if superclass.equal?(Object)
        raise NotImplementedError, "#{inspect} is an abstract type"
      else
        super
      end
    end

    # Create abstract instance methods
    #
    # @example
    #   class Foo
    #     include Abstract
    #
    #     # Create an abstract instance method
    #     abstract_method :some_method
    #   end
    #
    # @param [Array<#to_s>] names
    #
    # @return [self]
    #
    # @api public
    def abstract_method(*names)
      names.each { |name| create_abstract_instance_method(name) }
      self
    end

    # Create abstract singleton methods
    #
    # @example
    #   class Foo
    #     include Abstract
    #
    #     # Create an abstract instance method
    #     abstract_singleton_method :some_method
    #   end
    #
    # @param [Array<#to_s>] names
    #
    # @return [self]
    #
    # @api private
    def abstract_singleton_method(*names)
      names.each { |name| create_abstract_singleton_method(name) }
      self
    end

  private

    # Create abstract singleton method
    #
    # @param [#to_s] name
    #   the name of the method to create
    #
    # @return [undefined]
    #
    # @api private
    def create_abstract_singleton_method(name)
      singleton_class.class_eval do
        define_method(name) do |*|
          raise NotImplementedError, "#{inspect}.#{name} is not implemented"
        end
      end
    end

    # Create abstract instance method
    #
    # @param [#to_s] name
    #   the name of the method to create
    #
    # @return [undefined]
    #
    # @api private
    def create_abstract_instance_method(name)
      define_method(name) do |*|
        raise NotImplementedError, "#{self.class.inspect}##{name} is not implemented"
      end
    end

  end # module ClassMethods
end # module Abstract<commit_msg>Fix invalid example code<commit_after># encoding: utf-8

require 'backports'

# Module to allow class and methods to be abstract
module AbstractType

  # Hook called when module is included
  #
  # @param [Module] descendant
  #   the module or class including AbstractType
  #
  # @return [undefined]
  #
  # @api private
  def self.included(descendant)
    super
    descendant.extend(ClassMethods)
  end

  private_class_method :included

  module ClassMethods

    # Instantiate a new object
    #
    # Ensures that the instance cannot be of the abstract type
    # and must be a descendant.
    #
    # @example
    #   object = AbstractType.new
    #
    # @return [Object]
    #
    # @api public
    def new(*)
      if superclass.equal?(Object)
        raise NotImplementedError, "#{inspect} is an abstract type"
      else
        super
      end
    end

    # Create abstract instance methods
    #
    # @example
    #   class Foo
    #     include AbstractType
    #
    #     # Create an abstract instance method
    #     abstract_method :some_method
    #   end
    #
    # @param [Array<#to_s>] names
    #
    # @return [self]
    #
    # @api public
    def abstract_method(*names)
      names.each { |name| create_abstract_instance_method(name) }
      self
    end

    # Create abstract singleton methods
    #
    # @example
    #   class Foo
    #     include AbstractType
    #
    #     # Create an abstract instance method
    #     abstract_singleton_method :some_method
    #   end
    #
    # @param [Array<#to_s>] names
    #
    # @return [self]
    #
    # @api private
    def abstract_singleton_method(*names)
      names.each { |name| create_abstract_singleton_method(name) }
      self
    end

  private

    # Create abstract singleton method
    #
    # @param [#to_s] name
    #   the name of the method to create
    #
    # @return [undefined]
    #
    # @api private
    def create_abstract_singleton_method(name)
      singleton_class.class_eval do
        define_method(name) do |*|
          raise NotImplementedError, "#{inspect}.#{name} is not implemented"
        end
      end
    end

    # Create abstract instance method
    #
    # @param [#to_s] name
    #   the name of the method to create
    #
    # @return [undefined]
    #
    # @api private
    def create_abstract_instance_method(name)
      define_method(name) do |*|
        raise NotImplementedError, "#{self.class.inspect}##{name} is not implemented"
      end
    end

  end # module ClassMethods
end # module AbstractType
{'fraction_non_alphanumeric': 0.08288928359976318, 'fraction_numerical': 0.00039471087428458656, 'mean_word_length': 2.252888318356868, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3472897', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1516, 'n_words': 438}