From: Simon Strandgaard Date: 2004-04-30T08:50:37+09:00 Subject: Re: File.expand_path(__FILE__) On Fri, 30 Apr 2004 05:28:43 +0900 John Platte wrote: > I'm having a problem with File.expand_path(__FILE__) after a chdir. > Looks like a bug in Ruby to me. If someone can tell me what I'm doing > wrong, I'd be grateful. > > Here's the reduction: > > [ryan@kursk 15:26:38 ~]$ cat tmp/demo-problem.rb > puts "starting working directory: " + Dir.getwd > puts "expand_path: " + File.expand_path(__FILE__) > puts "about to change to dirname of __FILE__: " + __FILE__ > Dir.chdir(File.dirname(__FILE__)) > puts "new working directory: " + Dir.getwd > puts "expand_path: " + File.expand_path(__FILE__) ^^^^^^^^ BOOM I guess you assume that __FILE__ change when doing chdir. But it doesn't server> ruby a.rb "a.rb" "/tmp" "a.rb" "/" "a.rb" "/tmp" server> expand -t2 a.rb p __FILE__, Dir.pwd Dir.chdir("..") do p __FILE__, Dir.pwd end p __FILE__, Dir.pwd server> As you can see, filenames doesn't change during chdir. HTH, -- Simon Strandgaard