Skip to content

Instantly share code, notes, and snippets.

@r38y
Created November 12, 2010 17:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r38y/674420 to your computer and use it in GitHub Desktop.
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
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