From: Austin Ziegler Date: 2011-06-10T21:35:24+09:00 Subject: [ruby-core:36920] Re: [Ruby 1.9 - Feature #4824] Provide method Kernel#executed? On Thu, Jun 9, 2011 at 3:49 PM, Cezary Baginski wrote: > Issue #4824 has been updated by Cezary Baginski. > This may seem like heresy, but isn't really: > > �__FILE__ == $0 > > just a hack for letting a file be *both* a script and a "library" at the same time? With the only sane use (I can think of) being adding unit tests? > > This was probably useful in the early years of Ruby, but now with the internet, social coding, methodologies, TDD, BDD, packaging (gems), etc. - doesn't it make more sense to have tests and scripts in separate files? > > Why add a construct for handling a block of code that cannot be called in any other way, than running the script directly, creating dead code that isn't included in coverage? I use this in some code that I've written to allow a script to be run standalone or in the context of irb. I've even done some magic to allow the script to reexec itself in an IRB context. Tests are most *certainly* not the only good reason for this feature, and I would regret its departure. Of the suggestions proposed so far, I prefer __MAIN__ or __FILE__.main? to anything else. However, the code I mentioned above still needs to use $0/$PROGRAM_NAME in order to know whether it should build (or require) the irbshell support code that it uses. -a -- Austin Ziegler � halostatue@gmail.com � austin@halostatue.ca http://www.halostatue.ca/ � http://twitter.com/halostatue