From: dblack@... Date: 2006-03-18T01:53:57+09:00 Subject: Re: Explanation of if __FILE__ == $0 Hi -- 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 -- David A. Black (dblack@wobblini.net) 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