From: Joel VanderWerf Date: 2005-02-22T15:18:55+09:00 Subject: Re: Require when Executed file is required by another file. Zev Blut wrote: > On Tue, 22 Feb 2005 04:42:03 +0900, Joel VanderWerf > wrote: > >> Zev Blut wrote: >> >>> A coworker of mine just commented why not just use File.expand_path for >>> the required file? Is there any reason not to do this? >> >> >> Symlinks... >> >> $ cd /tmp >> $ touch foo >> $ ln -s foo bar >> $ ruby -e 'p File.expand_path("foo")' >> "/tmp/foo" >> $ ruby -e 'p File.expand_path("bar")' >> "/tmp/bar" > > > Yes that is true, but I noticed if you actually go to directory with > a symlink, it will expand to the true path. Like so: > > $ cd /tmp/ > $ mkdir foo > $ ln -s foo bar > $ touch foo/baz.rb > $ ruby -e 'Dir.chdir("foo") ;p File.expand_path("baz.rb")' > "/tmp/foo/baz.rb" > $ ruby -e 'Dir.chdir("bar") ;p File.expand_path("baz.rb")' > "/tmp/foo/baz.rb" > > Is this portable or are there other problems with doing it this way? Hm, I didn't expect that. And also: $ ruby -e 'Dir.chdir("bar") ;p Dir.pwd' "/tmp/foo" In the shell (using linux, zsh) it works differently: $ cd bar $ pwd /tmp/bar Another data point: $ ruby -e 'Dir.chdir("bar"); puts `pwd`' /tmp/foo I guess ruby follows symlinks when doing Dir.chdir? Anyway, it doesn't solve the problem of a symlinked .rb file, if that's a problem.