Sha256: 578a8cc9764bcb0507494d85aca4f3f1d2010e042d37ecb7f61f657829d3004b

Contents?: true

Size: 858 Bytes

Versions: 3

Compression:

Stored size: 858 Bytes

Contents

module Veritas
  module AbstractClass

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

    module ClassMethods

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

    end # module ClassMethods
  end # module AbstractClass
end # module Veritas

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
veritas-0.0.3 lib/veritas/support/abstract_class.rb
veritas-0.0.2 lib/veritas/support/abstract_class.rb
veritas-0.0.1 lib/veritas/support/abstract_class.rb