Hi --

On Thu, 17 Sep 2009, Dylan Lukes wrote:

> 7stud -- wrote:
>> 7stud -- wrote:
>>> Where is the plugin() method?
>>
>> ruby is telling you, "Hey guy who names every variable 'plugin'!
>> There's no plugin method defined anywhere."
>
> Correct, there is no plugin method. Here is some slightly modified code
> and the variables it references:

First of all, let's make Ruby do more of the work :-) This is
untested, but I think it will give you at least some ideas on how to
neaten up the code. In particular, note that there's probably no
reason to convert the classes back and forth from strings. (Even if
you need to do that, just use the #name method.)

module Plugin
   def initialize(server, config)
   end

   def run
   end
end

class BackupPlugin
   include Plugin
end

class MessagePlugin
   include Plugin
end

class KickPlugin
   include Plugin
end

PLUGINS = [
   BackupPlugin,
   MessagePlugin,
   KickPlugin
]

CONFIG = {
   BackupPlugin => {
     "interval" => (30 * 60),
     "directory" => "backups"
   }
}

class MyServer
   def start_plugins
     PLUGINS.map {|plugin| plugin(self, CONFIG[plugin]) }  # !!!!
   end
end

Of course, the problem is still there. What exactly do you want to do?
plugin is a class. Do you want an instance of it? If so:

   plugin.new(self, CONFIG[plugin])

One way or another, you need a method name.


David

-- 
David A. Black, Director
Ruby Power and Light, LLC (http://www.rubypal.com)
Ruby/Rails training, consulting, mentoring, code review
Book: The Well-Grounded Rubyist (http://www.manning.com/black2)