Module: Abstractize
- Defined in:
- lib/abstractize.rb,
lib/abstractize/version.rb
Overview
Mixin for abstract classes
Constant Summary collapse
- VERSION =
'0.1.2'.freeze
Class Method Summary collapse
Class Method Details
.abstract_method ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/abstractize.rb', line 22 def abstract_method lambda do |name| define_method(name) do |*_args| fail AbstractError, 'not implemented' end end end |
.abstract_new(base) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/abstractize.rb', line 15 def abstract_new(base) lambda do |*args| fail AbstractError, "cannot instanciate #{name}" if self == base super(*args) end end |
.included(base) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/abstractize.rb', line 6 def self.included(base) (class << base; self; end).instance_eval do define_method(:new, Abstractize.abstract_new(base)) define_method(:define_abstract_method, Abstractize.abstract_method) end end |