From: Jamis Buck Date: 2003-12-11T14:33:59+09:00 Subject: Re: Ideas for replacing $0==__FILE__ Austin Ziegler wrote: >>I like that--in fact, I'd probably use it. What happens if there are >>multiple TEST{} blocks (especially in required files)? Do they all get >>executed? >> >> > >I would suggest yes. Perhaps -t and -tr (e.g., -t only runs the last; -tr >runs all). What was brought up on #ruby-lang is whether the TEST {} blocks >would be exclusive, overriding normal behaviour. This may be desirable. > > Exclusive, meaning regular code (ie, code outside of TEST{}) would not run? I don't know if I like that. If that's what is needed, then it sounds like what is really needed is better separation of real and test code. I can see the value of TEST{}. But if you need something that only gets run during testing, and excludes the real application code... I don't know if such a language construct belongs in Ruby. Seems too specific to me. On a slightly related, albeit more general, note: what if there were a mechanism whereby the invoked script could handle options that were passed to the Ruby interpreter, and which the interpreter didn't understand? That is to say, instead of making -t and -tr actual flags in the interpreter, what if it were possible to make them accessible to (for instance) a module that the script 'requires'? Then the script could set a $TEST flag, define the behavior of the TEST method, and have all TEST{} blocks be executed when the script is run, as long as -t was passed to the interpreter. Perhaps it's just too late and I need to go to bed. -- Jamis Buck jgb3@email.byu.edu ruby -h | ruby -e 'a=[];readlines.join.scan(/-(.)\[e|Kk(\S*)|le.l(..)e|#!(\S*)/) {|r| a << r.compact.first };puts "\n>#{a.join(%q/ /)}<\n\n"'