From: Gavin Sinclair Date: 2003-12-11T11:12:30+09:00 Subject: Re: Ideas for replacing $0==__FILE__ > > I've recently found that it is sometimes useful to combine a "main" Ruby > program with required modules into a single file. I'm not entirely sure what you mean here. Can we have an example? > [...] > Do people really consider this idiom to be *that* useful? Most of the > times I've seen it used, it wraps either examples (better done in > separate files, you can have more than one and more complex), or tests > (*much* better done with Test::Unit). I commonly wrap Test::Unit tests in 'if $0 == __FILE__'. It's easier to edit and execute the tests when they're in the same file. It's less files in the distribution and no 'how do I include the library in the library path from the unit test file?' hassles. Concerning the idiom itself, I initially thought it ugly and pondered the benefit of a "main" function (i.e. at the top level, def main(*args)). Having come to appreciate the importance of runtime in Ruby, though, I now think it is appropriate for programmers to be aware of, and take control of, what happens when their files are loaded, and in what context. Therefore I find the idiom aesthetically unappealing but conceptually acceptable. Given this, I have little taste for the proposed __MAIN__, __TEST__, etc. directives. Gavin