Created
November 12, 2010 17:49
-
-
Save r38y/674420 to your computer and use it in GitHub Desktop.
How to declare which methods should be defined in a subclass of an abstract class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Abstract | |
def abstract_methods(*args) | |
args.each do |name| | |
class_eval(<<-END, __FILE__, __LINE__) | |
def #{name}(*args) | |
raise NotImplementedError.new("You must implement #{name}.") | |
end | |
END | |
end | |
end | |
end | |
class LineItem | |
extend Abstract | |
abstract_methods :name | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment