From: Brian Candler Date: 2003-04-05T23:35:02+09:00 Subject: Re: Plugins (sort off) On Sat, Apr 05, 2003 at 11:09:50PM +0900, Damphyr wrote: > Class Experiment > def doMethod(nameofmethod) > self.extend nameofmethod > end > end > > the above does not execute (I know, I tried :)) ) and it would be silly > if it did (I guess I'm a bit silly for trying :) ). > And that is what that > > very_clever_method_takes_string_returns_module(modulename) > > should do. Ah - I thought you were going to return the module itself, not a string of the module name. See Guy's response about const_get. There is always the string version of eval: eval "extend #{nameofmodule}" but I feel that to be rather kludgy, if not downright dangerous. Something else which might be useful in your toolbox is Kernel#autoload: # file1.rb module Foo def bar puts "hello" end end # main.rb autoload :Foo, "file1.rb" a="abc" b="def" a.extend Foo b.extend Foo a.bar #>> "hello" b.bar #>> "hello" This has the advantage of only pulling in the source files when required, as long as you know in advance what the module names are. Regards, Brian.