module PluginManager
@plugins = []
def self.<<(plugin)
@plugins << plugin
end
def self.plugins
@plugins
end
end
class Plugin
def self.inherited(klass)
PluginManager << klass.new
end
end
class Whatever < Plugin
end
PluginManager.plugins # => [#<Whatever:0x28564>]
Refactorings
No refactoring yet !
Adam
May 13, 2009, May 13, 2009 23:49, permalink
require 'singleton'
class PluginManager < Array
include Singleton
end
class Plugin
def self.inherited(klass)
PluginManager.instance << klass.new
end
end
Tj Holowaychuk
May 13, 2009, May 13, 2009 23:51, permalink
haha:
module Plugin end module Whatever include Plugin end p Foo.ancestors
samnardoni.myopenid.com
May 16, 2009, May 16, 2009 18:08, permalink
@Tj Holowaychuk, I don't think you understand what I'm getting at...
I'm trying to find a simple way to create a plugin architecture. Preferably: as soon as the class is inherited, it's added to the plugin manager. I'm thinking that PluginManager is in the biggest need of a cleanup.