module Unparser::AbstractType
Module to allow class and methods to be abstract
Original code before vendoring and reduction from: github.com/dkubb/abstract_type.
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/unparser/abstract_type.rb, line 35 def self.create_new_method(abstract_class) abstract_class.define_singleton_method(:new) do |*args, &block| if equal?(abstract_class) fail NotImplementedError, "#{self} 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/unparser/abstract_type.rb, line 17 def self.included(descendant) super create_new_method(descendant) descendant.extend(AbstractMethodDeclarations) end