Hi --

On Fri, 18 Sep 2009, Dylan Lukes wrote:

> David A. Black wrote:
>> Hi --
>>
>> On Fri, 18 Sep 2009, Dylan Lukes wrote:
>>
>>>> David
>>>       print "#{self} initialized with config:\n\n #{config}\n"
>>>  }
>>>
>>> #<KickPlugin:0x23ed8> initialized with config:
>>>
>>>
>>> Plugins started...
>>
>> That's because CONFIG's keys are strings. Look at the rewrite I did
>> earlier; I changed them to class objects. There's no point doing a
>> round-trip to string if you really need the class.
>>
>>
>> David
>
> I'm not round tripping. I took most of your advice in your rewrite, such
> as using name and so on.
>
> I still need to pass the configuration as a parameter to their
> initialization though. The only problem is the inherited initialize from
> the module Plugin does not seem to be properly getting the config
> parameter.

In your previous message, you had:

     PLUGINS.each {|plugin| plugin = plugin.new(self, CONFIG[plugin])}
and

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

The PLUGINS array contains class objects; the CONFIG hash has keys
that are strings. If I do this:

   hash = { SomeClass => "some stuff" }

and then I do:

   hash["SomeClass"]

I'll get nil, because the hash key is a class object, not a string.


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)