Created
December 11, 2012 16:40
-
-
Save Ptico/4260152 to your computer and use it in GitHub Desktop.
A tribute to abstract classes
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(meth, args=[]) | |
define_method(meth.to_sym) do |*params| | |
raise NotImplementedError, "method ##{meth} should be implemented with arguments (#{ args.join(', ') })" | |
end | |
end | |
end | |
class Hello | |
extend Abstract | |
## | |
# Say something to the world | |
# | |
# Params: | |
# - msg {String} Message to say (default: "World") | |
# - name {String} Your name (optional) | |
# | |
abstract :say, [:msg, :name] | |
end | |
Hello.new.say("Hello", "Ptico") #=> NotImplementedError: method #say should be implemented with arguments (msg, name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment