The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Plugins in your Ruby application

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eigen Class

Posts: 358
Nickname: eigenclass
Registered: Oct, 2005

Eigenclass is a hardcore Ruby blog.
Plugins in your Ruby application Posted: Jun 30, 2006 1:35 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Eigen Class.
Original Post: Plugins in your Ruby application
Feed Title: Eigenclass
Feed URL:
Feed Description: Ruby stuff --- trying to stay away from triviality.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eigen Class
Latest Posts From Eigenclass


I remember spending some time implementing a plugin framework in C++ some ~10 years ago. Things have changed greatly since, and when I had to do the same in Ruby some days ago for my Ruby script for the wmii window manager it took me but a few minutes.


This is yet another task that becomes so easy in Ruby it seems to fade out, so to say, the same way many design patterns are trivial and hardly deserve to be named anymore.

There are at least two things a plugin framework should do:

  • allow the user to drop plugins into some directory and have them loaded
  • register the functionality exposed by each plugin so as to use it either automatically or on demand

The first part is but a simple iteration

Dir["#{PLUGIN_DIR}/*.rb"].each{|x| load x }


As for the second, there are many ways to do it, but it definitely looks better when plugin registration is automagical and the plugin definition seems purely declarative. Several ideas come to mind, as there are quite a few hooks we can use for that.


Class#inherited is the most obvious choice (I feel); it'd look like this

class PluginBase
  def self.inherited(child)
    # register child somewhere
    # just to give a complete example:
    PluginBase.registered_plugins << child
  @registered_plugins = []
  class << self; attr_reader :registered_plugins end


Read: Plugins in your Ruby application

Topic: Journaled Domain Models via the Command Pattern, or, It's All Just CRUD pt. II Previous Topic   Next Topic Topic: Discovering a world of resources

Sponsored Links


Copyright © 1996-2018 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use