At Fri, 2 Aug 2002 07:33:03 +0900, <bbense+comp.lang.ruby.Aug.01.02 / telemark.stanford.edu> wrote: > When writing libraries for other programs to use > is it better to include any outside requirements > within the Class definition or outside it? i.e. > > [1] > require "foo" > > Class Bar > > > end > > or > > [2] > Class Bar > require "foo" > > > > end [1] and [2] have the same effect for ruby interpreter at all because namespace will not be nested by `require' or `load'. A human may get a little different sense from them: [1] says `this library or script requires "foo"' whereas [2] says `this definition of class Bar requires "foo"'. But this is a problem of taste or calture. [1] can list all required libraries on the top of a program but [2] doesn't. That may helps the reader expect something to use. On the other hand, [2] points what feature depends on the libraries but [1] doesn't. That may be helpful to track the dependency (hopefully correct). There is another story if `require' is put in def statement. Inside of def would not be evaluated until the method is invoked. So require in def can postpone loading a library file until really needed. That may improve average performance in some cases. -- Gotoken