Module: AbstractClass
- Defined in:
- lib/abstract_class.rb,
lib/abstract_class/version.rb
Overview
Declares a class as abstract which prevents instantiation or allocation.
Constant Summary collapse
- Error =
The exception raised when an abstract class is instantiated or allocated.
Class.new(RuntimeError)
- VERSION =
'1.0.1'
Class Method Summary collapse
Instance Method Summary collapse
-
#abstract_classes ⇒ Object
Stores a collection of classes that have been declared as abstract.
-
#allocate(*args) ⇒ Object
Raises Error if the class is abstract.
-
#new(*args) ⇒ Object
Raises Error if the class is abstract.
Class Method Details
.extended(mod) ⇒ Object
8 9 10 |
# File 'lib/abstract_class.rb', line 8 def self.extended(mod) mod.abstract_classes << mod end |
Instance Method Details
#abstract_classes ⇒ Object
Stores a collection of classes that have been declared as abstract.
13 14 15 |
# File 'lib/abstract_class.rb', line 13 def abstract_classes @@abstract_classes ||= [] end |
#allocate(*args) ⇒ Object
Raises Error if the class is abstract
18 19 20 |
# File 'lib/abstract_class.rb', line 18 def allocate(*args) raise_if_abstract(:allocated) { super } end |
#new(*args) ⇒ Object
Raises Error if the class is abstract
23 24 25 |
# File 'lib/abstract_class.rb', line 23 def new(*args) raise_if_abstract(:instantiated) { super } end |