Created
June 15, 2014 21:05
-
-
Save zapnap/21bae73bf31b943ab4ea to your computer and use it in GitHub Desktop.
abstract base class mixin
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 AbstractMethods | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
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 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment