module AbstractType

Module to allow class and methods to be abstract

Constants

VERSION

Gem version

Private Class Methods

create_new_method(abstract_class) click to toggle source

Define the new method on the abstract type

Ensures that the instance cannot be of the abstract type and must be a descendant.

@param [Class] abstract_class

@return [undefined]

@api private

Calls superclass method
# File lib/abstract_type.rb, line 32
def self.create_new_method(abstract_class)
  abstract_class.define_singleton_method(:new) do |*args, &block|
    if equal?(abstract_class)
      fail NotImplementedError, "#{inspect} is an abstract type"
    else
      super(*args, &block)
    end
  end
end
included(descendant) click to toggle source

Hook called when module is included

@param [Module] descendant

the module or class including AbstractType

@return [undefined]

@api private

Calls superclass method
# File lib/abstract_type.rb, line 14
def self.included(descendant)
  super
  create_new_method(descendant)
  descendant.extend(AbstractMethodDeclarations)
end