Skip to content

Instantly share code, notes, and snippets.

@Ptico
Created December 11, 2012 16:40
Show Gist options
  • Save Ptico/4260152 to your computer and use it in GitHub Desktop.
Save Ptico/4260152 to your computer and use it in GitHub Desktop.
A tribute to abstract classes
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