From: Eric Hodel Date: 2008-04-16T18:17:39+09:00 Subject: Re: How to reliably setup require path On Apr 16, 2008, at 00:50 AM, Christian Johansen wrote: > Joel VanderWerf wrote: >> Eric Hodel wrote: >>> The simplest way is `ruby -Ilib bin/myapp` from the root of the >>> project >>> dir. >>> >>> (-I directories take precedence over RUBYLIB directories.) >> >> Also, it's fragile with respect to the cwd. You have to be in >> myapp/ to >> run it, and also the program can't Dir.chdir without breaking the >> reference to the lib dir. > > Exactly, and this was my original problem as well.I think I'll go with > Eric Hodels solution for now. Also, I will put the code behind the > binary in myapp/lib/myapp/command.rb My solution works if ordinarily you distribute myapp as a gem as you avoid the problems with it that Joel pointed out. > I have organized my files such that mostly there's one class per file. > This means modules are spread over several files. Is it a good idea to > create a file named after each module which requires all the files > belonging to the module? If I would use it, I make such a file. Sometimes I don't need such a thing, but I always have a top-level one. > Then I could require all the modules in myapp/lib/myapp.rb so that > require 'myapp' from another app will give direct access to all my > classes and modules. Is it good? :) This is a very common practice.