in reply to conditional self-execution

OK -- after reading and re-reading the first sentence of your post, I think I understand the concept.

So what's the point? It just strikes me as a clever piece of code, a solution looking for a problem. It makes more sense to me to just write a module, which is really just a library of related subroutines and variables, and call it from a script, which is just the main-line.

And I'm asking this in the nicest possible way -- I'm not trashing Ruby, just I'm really puzzled as to why one would write something like this.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re^2: conditional self-execution
by apotheon (Deacon) on Jan 30, 2008 at 11:17 UTC

    I get the feeling that, the more you get used to the idea of having that option, the more you'll find things that could be done better if you aren't afraid to use that option when it's available.

    In my personal case, though, the primary use so far has been for unit tests.

    print substr("Just another Perl hacker", 0, -2);
    - apotheon
    CopyWrite Chad Perrin

Re^2: conditional self-execution
by djberg96 (Acolyte) on Jan 31, 2008 at 01:04 UTC
    First, it's not common. I personally only use it for tinkering but I don't publish that code. A few people use it as a place to put their unit tests, though that's still unusual.