Sha256: 26a6363fceca3d80c70519a6ee0868f07b30252da289ff5e3f754b05846db52a

Contents?: true

Size: 877 Bytes

Versions: 1

Compression:

Stored size: 877 Bytes

Contents

# encoding: utf-8

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

1 entries across 1 versions & 1 rubygems

Version Path
veritas-0.0.4 lib/veritas/support/abstract_class.rb