Skip to content

Instantly share code, notes, and snippets.

@zapnap
Created June 15, 2014 21:05
Show Gist options
  • Save zapnap/21bae73bf31b943ab4ea to your computer and use it in GitHub Desktop.
Save zapnap/21bae73bf31b943ab4ea to your computer and use it in GitHub Desktop.
abstract base class mixin
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