On 07.11.2009 05:21, David Masover wrote:
> On Friday 06 November 2009 04:08:45 am Robert Klemme wrote:
>> 2009/11/5 Don French <dhf0820 / gmail.com>:
>>> Ok, that gives me the list of the files. how do I execute a known
>>> class method call it self.identify in each of them, these are all of
>>> the same class. That is still the part I do not understand.
>> I typically find it easier to use a registration process, e.g.
>>
>> in mod1.rb:
>>
>> class X
>>   def self.identify; "foo"; end
>> end
>>
>> ::MODULES << X
> 
> I usually like to do that implicitly. For example, all these files probably 
> have something in common, or they wouldn't be called this way. Make them 
> either inherit from a common ancestor or include a common module. Here's how 
> to do it with a module:

Of course, the process can be improved.  Thanks for the suggestions.  My 
main point was to not reach from the outside into the file but rather 
reverse the process, i.e. code in the file announces its availability.

One just needs to make sure that deeper inheritance is handled in the 
way as intended.

> Another possibility would be to enforce a strict naming convention -- for 
> example, if there's a foo.rb, you assume it contains a Foo class. You could do 
> something like:

Something I'd rather not do because finding things about naming 
conventions and const_get is probably among the most unobvious and 
difficult to understand approaches.

Kind regards

	robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/