From: Timothy Bauscher Date: 2003-02-24T08:18:51+09:00 Subject: dynamic include I'm developing a program which needs to dynamically load and unload modules, adding the methods of each module to a class. ``include'' is giving me trouble. The following seems logical to me, but "include" isn't known inside the method: class Quinn def quinn_loadModule(modname) load "modules/#{modname}.rb" include #{modname} end end The following also doesn't work as I expected it to. Although it executes without error, the methods in the module are not extended into the class: class Quinn < Module def quinn_loadModule(modname) load "modules/#{modname}.rb" include #{modname} end end The following works, but it feels dirty: class Quinn def quinn_loadModule(modname) require "ftools" tmp = File::new("module.tmp", "w+") tmp.puts "load \"modules/#{modname}.rb\"" tmp.puts "include #{modname}" tmp.close load "module.tmp" File::safe_unlink("module.tmp") end end I'm aware of extend_object(), but requiring modules to add themselves to a particular object, IMO, takes away the modularity from a module. Any ideas are welcome. -- timothy(at)linuxfromscratch.org -*- "Share and Enjoy" || "Go stick your head in a pig" -*-