Aleksi Niemel<aleksi.niemela / cinnober.com> writes: > /* is*-routines return boolean (that is 0 or 1), > and we want to print "ok" if at least four of the tests passes */ > if( isPerfect() + isBeautiful() + isWonderful() + > isNotTooBad() + isEasy() + isOhInRuby() > 6-2 ){ > printf("ok"); > } In C, non-zero is true, so you'd better be really sure of your predicate routines for this to work! > One can accomplish equivalent functionality with > > if [isPerfect, isBeautiful, isWonderful, > isNotTooBad, isEasy, isOhInRuby].filter{ > |x| nil if x == true; x}.compact!.length <= 2 > print "ok" > end > > But I'm sure someone else agrees it's quite a bit harder and uglier (while > I'm not saying C-version isn't ugly :). True, but this version if [isPerfect, isBeautiful, isWonderful, isNotTooBad, isEasy, isOhInRuby].select{|x| x}.size <= 2 puts "ok" end Seems tidier than the C, and more flexible. It also honors the language's definition of true and false, which the C version doesn't. Dave