From: Trans Date: 2006-08-09T04:45:45+09:00 Subject: Re: load paths unions? Robert Klemme wrote: > On 08.08.2006 18:06, Trans wrote: > > I want to be able to "union" some load paths. Eg. given > > > > lib/facets/more > > lib/facets/core > > > > I'd like to be able to do > > > > require 'facets/foo.rb' > > > > And have it search both more/ and core/ for foo.rb. > > Usually you do > > require 'facets/foo' > > and have a file "xyz.rb" in facets that will link "more/foo.rb" or > "core/foo.rb" depending on where it's located. Yes, currently I a separate directory facet/ that I build automatically which contains nothing but require redirections: Eg. facet/foo.rb contains "require 'facets/core/foo.rb'". But there are a lot of files and I find it rather wasteful solution --at tlease two requires for every one. Plus I have to use a slighly different name -- 'facet' instead of 'facets'. > You could as well do this: create a file "facets.rb" in the same > directory that holds "facets" (i.e. lib). Inside of that you do > > def frequire(*names) > names.each do |name| > %w{more core}.any? do |base| > begin > require "facets/#{base}/#{name}" > true > rescue > false > end > end or raise LoadError, "Did not find #{name}" > end > end I don't want a seprate method, but I have consieder overriding #require. I just hoping there might be a better clever way. I hear Python supports .pth files which can redirect whole path reference to anther location. I wonder if Ruby could support something like this? T.