Skip to content

Instantly share code, notes, and snippets.

@adam-stokes
Forked from jm/plugin.rb
Created December 21, 2016 17:16
Show Gist options
  • Save adam-stokes/a81c9e07b294f2eaa4758fa0055eb2d1 to your computer and use it in GitHub Desktop.
Save adam-stokes/a81c9e07b294f2eaa4758fa0055eb2d1 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