Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

elliott cable http://elliottcable.name/

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

[ruby] plugin structure

plugin structure sorta thing. Use inherited to concatenate all plugins to a library in a Plugins constant in said library.

class Library
  Plugins = []
  
  def initialize#(...)
    Plugins.each do |plugin|
      # Here you can run a certain class method or grab some data from each class
    end
  end
  
  # ...
end


class LibraryPlugin
  # ...
  
  def self.inherited(sub); Library::Plugins << sub; end
end


class LibraryFooer < LibraryPlugin
  
end
class LibraryBarer < LibraryPlugin
  
end


Library::Plugins.inspect #=> [LibraryFooer, LibraryBarer]
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS