Can someone please explain to me the reason for Rails odd (to me) strategy of loading/requiring files? Specifically, I''m referring to two things: 1) Many generated files seem to have a require statement like this one: require File.dirname(__FILE__) + "/../config/environment". Why do this "relative to the current file" style of require? 2) Why add what looks like virtually every directory in the system into the LOAD_PATH, instead of simply a few core directories? Thanks David
On 5/21/05, David Corbin <dcorbin-wmGZ+vDKSyrZJqsBc5GL+g@public.gmane.org> wrote:> Can someone please explain to me the reason for Rails odd (to me) strategy of > loading/requiring files? > > Specifically, I''m referring to two things: > 1) Many generated files seem to have a require statement like this one: > require File.dirname(__FILE__) + "/../config/environment". Why do this > "relative to the current file" style of require?Because you are allowed to customise the contents of environment.rb, say to add application specific hooks into pre-existing classes etc. A system-wide file wouldn''t allow this.> 2) Why add what looks like virtually every directory in the system into the > LOAD_PATH, instead of simply a few core directories?Because the files are spread around all those directories? I don''t really follow what you''re saying here.> Thanks > David > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
On Friday 20 May 2005 10:49 pm, Michael Koziarski wrote:> On 5/21/05, David Corbin <dcorbin-wmGZ+vDKSyrZJqsBc5GL+g@public.gmane.org> wrote: > > Can someone please explain to me the reason for Rails odd (to me) > > strategy of loading/requiring files? > > > > Specifically, I''m referring to two things: > > 1) Many generated files seem to have a require statement like this one: > > require File.dirname(__FILE__) + "/../config/environment". Why do this > > "relative to the current file" style of require? > > Because you are allowed to customise the contents of environment.rb, > say to add application specific hooks into pre-existing classes etc. > A system-wide file wouldn''t allow this.I understand that, but why not "require ''config/environment''" or "require ''environment''", subject to my comment below.> > > 2) Why add what looks like virtually every directory in the system into > > the LOAD_PATH, instead of simply a few core directories? > > Because the files are spread around all those directories? I don''t > really follow what you''re saying here.Instead of adding all the directories ''app/models'' to the LOAD_PATH, with require ''foobar'', why not simply say "require ''models/foobar''? In general, It seems to me that Rails is "throwing away" a great deal of scoping that may be important in large project. David