From: Ken Kunz Date: 2006-09-28T07:10:14+09:00 Subject: Injecting truth I had a scenario arise today where I needed an iterator with similar semantics as Enumerable#all?, but non-short-circuiting. We came up with a fairly elegant solution (imho), so I thought I'd be a good rubyzen and share :) 1) First... the standard #all? (short-circuits): irb> (1..5).all? { |i| puts i; i < 3 } 1 2 3 => false 2) Non-short-circuiting version (injecting truth): irb> (1..5).inject(true) { |retval, i| puts i; retval &&= (i < 3) } 1 2 3 4 5 => false 3) One more way (though I like #2 better) irb(main):016:0> (1..5).partition { |i| puts i; i < 3 }.last.empty? 1 2 3 4 5 => false -Ken