On Thu, Jun 9, 2011 at 3:49 PM, Cezary Baginski
<cezary.baginski / gmail.com> wrote:
> Issue #4824 has been updated by Cezary Baginski.
> This may seem like heresy, but isn't really:
>
> =A0__FILE__ =3D=3D $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 int=
ernet, social coding, methodologies, TDD, BDD, packaging (gems), etc. - doe=
sn'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 i=
sn'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
--=20
Austin Ziegler =95 halostatue / gmail.com =95 austin / halostatue.ca
http://www.halostatue.ca/ =95 http://twitter.com/halostatue