"Simon Strandgaard" <neoneye / adslhome.dk> schrieb im Newsbeitrag
news:20040501024546.78ef9b57.neoneye / adslhome.dk...
> "Ara.T.Howard" <ahoward / fattire.ngdc.noaa.gov> wrote:
> > On Sat, 1 May 2004, Simon Strandgaard wrote:
> [snip]
> > > I don't know if all this rethinking __FILE__/$0 makes sense..
> >
> > i think it makes perfect sense to have
> >
> >   __FILE__    => absolute path of script file
> >   __PROGRAM__ => absolute path of called program
> >   __RUBY__    => absolute path of ruby interp running called program
> >   __DIR__     => absolute directory of file (can use for relative
requires)

__DIR__ is superfluous if __FILE__ is absolute alreay.  File.dirname(
__FILE__ ) will do the job.

And I'd choose different names.  The __FILE__ and __LINE__ are there
because of CPP, there's no need to use these kind of names for new
semantics.

> > it's always easy get a relative path from an absolute one, but not the
other
> > way!
>
> This was what I wanted to express, though I could not write it in such a
striking
> sentence  :-)

I don't think that statement is true.  For both approaches (rel path ->
abs path and abs path -> rel path) you need an additional piece of
information, an additional path to relate to.  That said, both (the
relative path and the absolute path) lack information, which makes it
equally difficult to do the transformation (or let's say impossible
without this additional information).

> I don't know what is right nor wrong...
>
> Maybe make __FILE__ a class with a one useful method, #standalone?
> So that instead of 'if $0 == __FILE__' you can type 'if
__FILE__.standalone?'

I don't have statistics but this may brake too much code.

> Maybe make a System class, containing a $0 replacement?

I like the idea.  Maybe call it Runtime.  This could even be facilitated
in creating nested but independent interpreters etc.:

Runtime.current.interpreter
=> /usr/bin/ruby

Runtime.current.gc
=> 1023 (collected instances)

Runtime.current.used_mem
=> 12828379478

Runtime.new( "my_script.rb", "--verbose", "foo" )
=> Runtime

Regards

    robert