James Gray
2/23/2006 3:59:00 PM
On Feb 23, 2006, at 9:07 AM, Anthony DeRobertis wrote:
> Gregory Brown wrote:
>
>> On 2/22/06, Anthony DeRobertis <aderobertis@metrics.net> wrote:
>>> Take the following snippet:
>>
>> why do string conversion?
>>
>> You can pass constants around in ruby just fine.
>
> I'm scanning a directory for plugins and loading them. When I load a
> file called, for example, some_plugin.rb, I assume it creates a class
> Whatever::Plugins::SomePlugin, which I naturally only have as a
> string...
You can do this without using the name assumptions in Ruby, if you
give them a class to inherit from. Classes get notified when they
are subclassed:
>> class Plugin
>> def self.inherited( plugin_class )
>> (@@plugins ||= Array.new) << plugin_class
>> end
>> def self.loaded
>> @@plugins || Array.new
>> end
>> end
=> nil
>> class FirstPlugin < Plugin; end
=> nil
>> class SecondPlugin < Plugin; end
=> nil
>> Plugin.loaded
=> [FirstPlugin, SecondPlugin]
Hope that gives you some fresh ideas.
James Edward Gray II