From: sabbyxtabby@... (Sabby and Tabby) Date: 2003-03-10T19:44:14+09:00 Subject: Re: $0 == false ?? Tim Bates wrote in message news:<200303092049.04170.tim@bates.id.au>... > On Sun, 9 Mar 2003 6:29 pm, Tim Bates wrote: > > Without $0, how can I retrieve the name of the currently running script > > from within a require'd file? (ie, __FILE__ won't work...) Example: > > Okay, it seems I can use Apache.request.filename instead, but I'm still > curious about the clobbering of $0. You can also use 'caller' in the require'd file: # b.rb puts caller[0][/[^:]+/] As for why $0 gets clobbered, someone with *any* mod_ruby experience will have a better answer, but here are some guesses: 1. All scripts in mod_ruby are run under the same process as the Apache server? 2. All scripts share the same global variables? 3. Instead of returning $0 == 'foo.rb' for all scripts, mod_ruby punts? Again, all guesses. Would it be possible for mod_ruby to set $0 to Apache.request.filename just before running a script? BTW, how does mod_ruby set $0 to false? $0 = nil # ...failed to convert nil into String (TypeError) And, an off-topic challenge: anyone know how to get $0 to return the current time? puts $0 # Mon Mar 10 02:21:26 PST 2003 sleep 10 puts $0 # Mon Mar 10 02:21:36 PST 2003 -- Tabby