From: Jim Weirich Date: 2005-08-13T00:50:32+09:00 Subject: Re: LibInject 0.1.0: Small Pieces Smooshed Together Francis Hwang said: > Jim Weirich wrote: >> Cool! Does it handle things like this: >> >> class Command >> def create_option_parser >> require 'optparse' >> @parser = OptionParser.new >> ... >> end >> end > > Nope. It really only handles the simplest, most common case, of the > require statement being on its own line outside of any class/method > definitions. I could try to make it smart enough to pull require > statements out of class & method definitions, but I'm not certain if > it'd be worth the effort. Are there actually many libs out there that > use requires this way? I personally try to avoid just 'cause I think it > makes the code look messier, but obviously that's sort of just a > personal style thing. My personal style (in general) is to put all the requires at the top level at the beginning. However in RubyGems we use the above idiom often to avoid requiring things that are not needed. The optparse is a bad example because it is always (eventually) needed, but things like the compression libraries or the network http libraries are only required for certain variations of the gem command. By requiring them inline at the place they are used means they are not loaded when they are not needed. -- -- Jim Weirich jim@weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)