From: Richard Kilmer Date: 2004-06-17T12:53:08+09:00 Subject: Re: [OT] RE: require vs require_gem On 6/16/04 11:46 PM, "Sean O'Dell" wrote: >> What you describe doesn't quite follow the Ruby 'require' process. >> 'require' isn't the same as #include of java's import: you do not need >> to require a library from every file that uses it. Once you have >> require'd a file everything in it has already been brought in to the >> interpreter. >> >> For an app/lib type of work you describe, where users will always call >> through the "base file", you can just put all your requires there (or in >> one file called from the base). This has the advantage that you can deal >> with all external libraries and their versions in one place. > > I find it's better to spread out the requires (not too liberally), so you only > load libraries when they're really needed. Sometimes a program won't use > some of the "require" files, so it's possible to avoid unnecessary loading of > libraries it won't use. > I second that, and actually put some 'require' statements in methods right before I use them. That way if a method is called, the library is loaded, otherwise not: def load_from_yaml(filename) require 'yaml' YAML.load(File.read(filename)) end So if this method is called, yaml is loaded (if necessary), otherwise its not. -rich