Skip to content

Instantly share code, notes, and snippets.

@jm
Created July 6, 2013 14:59
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jm/5940145 to your computer and use it in GitHub Desktop.
Save jm/5940145 to your computer and use it in GitHub Desktop.
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