On Sat, 18 Mar 2006, PJ Hyett wrote:
So I’ve tracked this down:
FILE is the name of the current source file
$0 at the top level is the name of the top-level program being executed
But I’m still confused as to what this if statement is accomplishing?
It’s obviously useful for something since it’s used quite often. Does
this pertain to when a script is called from another script?
Yes; if FILE (the name of the current file) is the same as $0 (the
file where execution started), then you’re in the startup file.
You’ll often see this used in, say, a library file that usually gets
loaded from another file (so FILE == $0 is false), but can also be
run standalone for the sake of running tests.
David A. Black (email@example.com)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)
“Ruby for Rails” chapters now available
from Manning Early Access Program! http://www.manning.com/books/black