From: Brian Candler Date: 2009-08-25T22:11:38+09:00 Subject: Re: Packaging - distribution Pito Salas wrote: > David, > > Thanks for a sensational answer to my question! Great detail, very > informative. > >> $: << '/path/to/system/lib' >> require 'sub_alpha' >> >> In my opinion, that's much better than trying to do something like: >> >> require '/path/to/system/lib/sub_alpha.rb' > > I've seen the $: << construct; can you say a little about why it's much > better than putting the path directly in the require? > > My guess is that the path appears only once in the $: line so if it > changes you don't have to go changing a whole bunch of requires. Yes, or > is there something else more important? If one bit of code does "require 'sub_alpha'", and another bit of code does "require '/path/to/system/lib/sub_alpha'", then the file will be loaded twice. So you may see this pattern: require File.dirname(__FILE__)+"/../lib/sub_alpha" but I'd strongly recommend against it. BTW, $:.unshift is probably better than $: <<, because it will put your code at the front of the path. -- Posted via http://www.ruby-forum.com/.