From: Robert Klemme Date: 2004-03-04T17:49:48+09:00 Subject: Re: Ruby won, of course "Piergiuliano Bossi" schrieb im Newsbeitrag news:c26okp$q0i$1@lacerta.tiscalinet.it... > Robert Klemme wrote: > >> > >>**********************CUT HERE********************** > >>def check(*tests) > >> stack = caller.map {|m| m[/\w*(?=')/]}.compact.reverse.join " " > >> tests.inject(true) {|ret, t| puts "#{(v=eval(t)) ? 'pass' : > > > > 'FAIL'} > > > >>.... (#{stack}) #{t.strip}"; ret && v} > >>end > >>**********************CUT HERE********************** > >> > >>What do you think about it? > > > > > > - you're omitting the file info as far as I can see > > Yes, but that's not really needed, because: > stack = caller.map {|m| m[/\w*(?=')/]}.compact.reverse.join " " > does everything you need. > > > - I'd move the v=eval(t) out of the string replacement, no need to have it > > there. > > You are right. It's a bit longer, but much better in terms of > understandability. > > > + #inject is even more performant since you omit the intermediate array of > > results. > > Yes, even if the combine_results method performs all the check anyway, > while inject appears to stop as soon as a false value is reached. Not a > big issue, in any case. inject doesn't stop prematurely unless you include a break or return (which you didn't): irb(main):007:0> (1..10).inject(true){|acc,v|p v; acc && v < 5} 1 2 3 4 5 6 7 8 9 10 => false robert > Ciao, Giuliano > > -- > If you want to send me an email in the address you have to write 'p', > then a dot, followed by 'bossi' at 'quinary', another dot and 'com' at last >