From: Robert Klemme Date: 2010-08-29T21:55:07+09:00 Subject: Re: require from a method On 29.08.2010 13:11, Markus Fischer wrote: > Hi, > > On 29.08.2010 12:40, Robert Klemme wrote: >> On 29.08.2010 12:25, Ammar Ali wrote: >> >>> Are there any gotchas in requiring files from within a method? It >>> seems to work, but I have a sinking feeling that I'm missing something >>> here. >> >> Not technically. It might even be more efficient if you require a >> particular functionality only rarely and include the "require" in the >> method that needs that functionality. > > Sorry for hijacking, but I'm wondering how require exactly works in the > context of a class or method; does scoping play any role if I've defined > classes/modules in the required file? No. It would be bad because then if the require statements would be executed in a different order totally unpredictable behavior would occur. Robert@babelfish ~ $ echo 'p self' >x.rb Robert@babelfish ~ $ ruby19 -r x -e 1 main Robert@babelfish ~ $ ruby19 -r x -e 'class X; def m;require "x"; end; end; X.new.m' main Robert@babelfish ~ $ Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/