I'd like to puts a 1 if a test is true and a puts a 0 if it is not. I'd also like to increment a counter that counts each time a test is successful. I have this right now:
puts test1 ? sum += 1 : 0
puts test2 ? sum += 1 : 0
puts test3 ? sum += 1 : 0
puts test4 ? sum += 1 : 0
Obvoiusly the problem is that if i'm incrementing sum each time, then i'm not print 1 but rather the value of sum.
I tried making a little method that incremented sum and then returned 1 like this:
def inc_sum_ret_1(sum)
sum += 1
1
end
and called that in place of "sum += 1". This, of course, only incremented 0 to 1 each time.
Is there a good way to do this? I'm more curious from an intellectual standpoint than making my code particularly tidy.