From: Jano Svitok Date: 2007-07-03T06:03:29+09:00 Subject: Re: getting rid of $0 On 7/2/07, Michel Demazure wrote: > The common idiom > if __FILE__ == $0 then ... > gives bugs when $0 is not what one would expect, for instance under a > debugger, or in rubyscript2exe, etc. > > There should be a primitive test > if then... rcov provides for this case a special switch --replace-progname that does what the name says. Unfortunately, sometimes there's still a mismatch between those two: one is ./something.rb while the other is just something.rb. Therefore I use the following variation of the idiom (I haven't checked this under debugger or any other prog): if File.expand_path(__FILE__)==File.expand_path($0) I have posted a patch for ruby-prof that adds a similar switch and it has been accepted. Anyway, $0 seems to be a normal variable that you can set to anything you want, so creating a small wrapper script should not be a problem. E.g. $0 = ARGV.shift require $0