From: Robert Klemme Date: 2004-03-05T01:14:42+09:00 Subject: Re: Ruby won, of course "Piergiuliano Bossi" schrieb im Newsbeitrag news:c27fab$p4h$1@lacerta.tiscalinet.it... > Robert Klemme wrote: > >>>+ #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): > > You are right, my fault. Fact is that having eliminated combine_results > method I now combine values using '&&' (or 'and'), which in turn > performs a short-circuit evaluation ==> if the failing test is in the > first group combined through '&&' the second group will never be evaluated. > > I start thinking that combine_results cannot be avoided... I'm afraid you're a bit confused now. :-) What do you want combine_results for? It does not make a difference, because you eval'ed t before. And even if you didn't, switching order is sufficient. You did (with the slight modification of pulling v=eval(t) out of the string): def check(*tests) stack = caller.map {|m| m[/\w*(?=')/]}.compact.reverse.join " " tests.inject(true) {|ret, t| v=eval(t); puts "#{v ? 'pass' : 'FAIL'} ..... (#{stack}) #{t.strip}"; ret && v} end It doesn't matter whether "ret && v" short circuits or not, because you did eval it already. And even if you didn't you could do "eval(t) && ret" which would always eval. Regards robert