From: Chris Lowis Date: 2007-08-30T00:07:06+09:00 Subject: Help design a plugin system for a DSL Hello, I've been working through the "Creating DSLs with Ruby" tutorial here : http://www.artima.com/rubycs/articles/ruby_as_dsl4.html In my DSL I'd like users to be able to write code such as this : myDSL do plugin "extra_functions" a_special_function basic_function end that is, to extend the range of callable functions using a kind of "plugin" system. The code that I have to implement this so far looks like : class myDSL def initialize(name) @name = name end def self.load(name) dsl = new(name) dsl = dsl.instance_eval(File.read(name)) dsl end def myDSL yield end def plugin(file) puts "loading plugin: #{file}" require "./plugins/#{file}.rb" end def basic_function() # a "core" method of the DSL. end end which is called using a short loader file like this : require 'myDSL' name = ARGV.shift name = myDSL.load(name) In the extra_functions.rb "plugin" I have a method definition def a_special_function # does something special end I'm concerned that this is poor design, as the plugin functions will not be very well encapsulated. Requiring two plugins that define the same method names will cause the wrong methods to be called from the DSL. What is a sensible way to solve this problem ? My thought is to use method_missing to traverse plugin Classes in the order they were loaded, looking for the function called. Is this a good way to proceed ? Any other suggestions ? Chris -- Posted via http://www.ruby-forum.com/.