Module: Filigree::AbstractClass

Included in:
BasicPattern, MultipleObjectPattern, SingleObjectPattern
Defined in:
lib/filigree/abstract_class.rb

Overview

A module the implements the abstract class and abstract method patterns.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ void

This method returns an undefined value.

Tell the extended class to install its instance class variables.



86
87
88
# File 'lib/filigree/abstract_class.rb', line 86

def self.extended(klass)
  klass.install_icvars
end

Instance Method Details

#abstract_method(name) ⇒ void

This method returns an undefined value.

Declares a method with the given name. If it is called it will raise an AbstractMethodError.

Parameters:

  • name (Symbol)

    The name of the abstract method you with to declare



50
51
52
53
54
55
56
# File 'lib/filigree/abstract_class.rb', line 50

def abstract_method(name)
  abstract_class_name = @abstract_class.name

  define_method name do
    raise AbstractMethodError.new name, abstract_class_name
  end
end

#install_icvarsvoid

This method returns an undefined value.

Install instance class variables in the extended class.



61
62
63
# File 'lib/filigree/abstract_class.rb', line 61

def install_icvars
  @abstract_class = self
end

#new(*args) ⇒ Object

Raise an AbstractClassError if someone attempts to instantiate an abstract class.

Parameters:

  • args (Object)

    The arguments to initialize.

Raises:



71
72
73
74
75
76
77
# File 'lib/filigree/abstract_class.rb', line 71

def new(*args)
  if self.instance_variable_defined?(:'@abstract_class') and @abstract_class == self
    raise AbstractClassError, self.name
  else
    super
  end
end