-
-
Save adam-stokes/a81c9e07b294f2eaa4758fa0055eb2d1 to your computer and use it in GitHub Desktop.
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
class Plugin | |
def self.plugins | |
@plugins ||= [] | |
end | |
def self.inherited(klass) | |
@plugins ||= [] | |
@plugins << klass | |
end | |
# Usually a good idea for debugging if you have lots of methods | |
def handle_command(thing) | |
raise "#{self.class.name} doesn't implement `handle_command`!" | |
end | |
end | |
class Dog < Plugin | |
def handle_command(thing) | |
puts thing | |
end | |
end | |
Plugin.plugins.each do |plugin_class| | |
plugin_class.new.handle_command('test') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment