Brian Candler wrote:
> On Fri, Apr 04, 2003 at 08:25:25AM +0900, Damphyr wrote:
> 
>>In the actual app I read all files in the ./lib directory with a .module 
.......Removing unnecessary traffic volume........
>>class?
> 
> 
> I'm not sure how relevant this is to your application, but you could have a
> look at the way ruby-dbi handles loading of DBD drivers for different
> databases, which are effectively dbi "plugins". The user chooses the
> appropriate DBD driver with a selection string:
> 
>    db = DBI.connect("dbi:Mysql:test","root","")
>                          ^^^^^
> 
> That string locates the file (DBD/Mysql/Mysql.rb) which contains a module
> (DBI::DBD::Mysql). You don't worry about cross-pollution of the namespaces,
> because each module for each database driver has its own namespace.

I'll need to check it out, thanks for the reference.

> The other thing which might be useful for you is singleton classes:
> 
>   class Foo; end
>   module Bar; def test; puts "hello" end end
> 
>   a = Foo.new     # some object
>   a.extend Bar    # mixin module to this instance only
>   a.test
> 
> When you have finished with object 'a' you just forget the reference and it
> gets garbage collected. Then you can create a new object and mixin a
> different module next time. Perhaps this helps get over the need to remove a
> mixin.

That would be similar to the idea of creating a pool by creating empty 
classes.
My original requirement was to be able to drop in new modules at any 
time and be able to detect the change even at runtime (my example does 
not need runtime detection of drop-in modules, being a script so I 
restrained itself to startup detection :) )
So that means probably a clever mechanism for require-ing all files in a 
  plugin/ directory or somesuch hack (and detecting changes to that 
directory at runtime). But then, how do we change the parameter to 
extend to be able to say something like

module = myclass.very_clever_method_takes_string_returns_module(modulename)
a = Foo.new
a.extend module

In essence what I want is to be able to evaluate a string and find out 
if it matches a symbol (or the texual representation of a symbol to be 
more accurate) in my class space, and then return that symbol or the 
object/class/module for that symbol
V.-


--
http://www.freemail.gr - δωρεάν υπηρεσία ηλεκτρονικού ταχυδρομείου.