Problem
You want to define an abstract method that must be defined by a subclass or will throw an exception if used.
Solution
Use Abstract#method (defined below) and add the following call inside the definition of your class:
Abstract.method(:method_name)
Discussion
#!/usr/local/bin/ruby -w
FIX: make dynamic code. IO problems in RubyCodeRenderer prevent this.
module Abstract def Abstract.method(name, *args) code = “def #{name}(#{args}) raise "#{self.class}##{name} is abstract. Definition is a subclass responsibility." end” self.module_eval(code) end end
class Abstractclass include Abstract Abstract.method(:foo) end
class Concreteclass < Abstractclass def foo puts “Yeah!” end end
c = Concreteclass.new c.foo
c = Abstractclass.new c.foo
Contrast
TODO: CONTRAST
Related
TODO: LIST_OF_RELATED_ITEMS
Status: In Progress