A09a1dfb545dcd352d721ad0ea5aec3e

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.

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 !

A8d3f35baafdaea851914b17dae9e1fc

Adam

May 13, 2009, May 13, 2009 23:49, permalink

No rating. Login to rate!
require 'singleton'

class PluginManager < Array
  include Singleton
end

class Plugin
  def self.inherited(klass)
    PluginManager.instance << klass.new
  end
end
F1e3ab214a976a39cfd713bc93deb10f

Tj Holowaychuk

May 13, 2009, May 13, 2009 23:51, permalink

No rating. Login to rate!

haha:

module Plugin
  
end

module Whatever
  include Plugin
end

p Foo.ancestors
A09a1dfb545dcd352d721ad0ea5aec3e

samnardoni.myopenid.com

May 16, 2009, May 16, 2009 18:08, permalink

No rating. Login to rate!

@Tj Holowaychuk, I don't think you understand what I'm getting at...

Your refactoring





Format Copy from initial code

or Cancel