From: "Ara.T.Howard" Date: 2004-05-01T00:24:01+09:00 Subject: Re: File.expand_path(__FILE__) On Fri, 30 Apr 2004, John Platte wrote: > On 2004 Apr 30, at 9:39, Robert Klemme wrote: > > >> I see Perl uses relative paths for both __FILE__ and $0...and since a > >> lot of Ruby scripts use "if __FILE__ == $0", those two should keep > >> following the same policy. So I don't expect that behavior to change > >> for my odd little case. > > > > .... or operators are overloaded to ensure proper behavior. > > I can't imagine that would lead to increased predictability! > > On this topic, however, it'd be nice to have a method like > this_file_invoked? that encapsulated the $0 == __FILE__ idiom. > > >> Surely there's an existing solution to this within Ruby or Perl or > >> some > >> other language? > > > > See my other post: > > > > # at the top of script > > FILE = File.expand_path( __FILE __ ) > > Yes, that snippet was a workaround I was thanking you for, but I don't > consider it a solution to the problem: > > it seems we can't determine the absolute path of __FILE__ correctly > after a chdir without having planned for that eventuality before the > chdir. > > Can someone solve that one? what's wrong with this, i do it in all my programs: require 'pathname' class Main ... FILE = Pathname.new(__FILE__).realpath.to_s ... end what's wrong with solving it by planning for it? -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | URL :: http://www.ngdc.noaa.gov/stp/ | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done ===============================================================================