From: "Ara.T.Howard" Date: 2004-07-30T07:11:44+09:00 Subject: Re: Including other people's Ruby libs in your package On Fri, 30 Jul 2004, James Britt wrote: > What sort of project directory layout might work best? i use this layout a top level 'include' file. one versioned, one not. this allows me install multiple versions and do like 'require "package-0.0.0" when i want to link to a specific version. doing a 'require "package"' will always pick up the latest greatest. lib/package-0.0.0.rb lib/package.rb unless defined? $__package__ module Package LIBNAME = "package" VERSION = "0.0.0" LIBVER = "#{ LIBNAME }-#{ VERSION }" DIRNAME = File.dirname(File.expand_path(__FILE__)) + File::SEPARATOR ROOTDIR = File.dirname(DIRNAME) LIBDIR = File.join(DIRNAME, LIBVER) + File::SEPARATOR require LIBDIR + 'a' require LIBDIR + 'b' end $__package__ = __FILE__ end actual package impl lives in a versioned directory (for same reason as above). these files set alot of the same parameters as the include files. these vars allow me to do relative requires and also allow mutual requies. this is extremely nice for unit testing since each class can require independantly the files it needs with no fear of double requires do the the 'require "a" - require "a.rb"' bug. lib/package-0.0.0/a.rb unless defined? $__package_a__ module Package LIBDIR = File.dirname(File.expand_path(__FILE__)) + File::SEPARATOR unless defined? LIBDIR require LIBDIR + 'b' class A end end $__package_a__ = __FILE__ end lib/package-0.0.0/b.rb unless defined? $__package_b__ module Package LIBDIR = File.dirname(File.expand_path(__FILE__)) + File::SEPARATOR unless defined? LIBDIR require LIBDIR + 'a' class B end end $__package_b__ = __FILE__ end this seems a pain but i have code generator scripts to do the work. cheers. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================