From: David Masover Date: 2009-11-24T10:31:47+09:00 Subject: Re: What is __FILE__ and $0? (newbie question) On Monday 23 November 2009 07:18:12 pm Omar Campos wrote: > if __FILE__ == $0 > #main loop code > end > > I've already done some GUI apps, and had no need of these wierd > variables. But I am still curious, what do they mean? I'm not sure that would always work... $0 is probably named after the same variable in the shell -- it tells you how the current program was executed. __FILE__ is the name of the current file, wherever it's accessed. It seems that what they're trying to do is only run the main loop when your program is run as a program, and not when it's used as a library. That is, if your program is foo.rb, and you run it as foo.rb, __FILE__ will be 'foo.rb', and $0 will also be 'foo.rb', so the main loop will run. But if you then write a program called bar.rb, which requires foo, $0 will be 'bar.rb', but __FILE__ will still be 'foo.rb', so the main loop will not run. I'm not sure why I'd ever want to do that, but there you go.