From: Robert Klemme Date: 2012-02-10T21:59:40+09:00 Subject: Re: How does && work in ruby On Fri, Feb 10, 2012 at 1:18 PM, Phil Carter wrote: > Brilliant! That really helps, the bit I was missing is that it returns > the last operand if both are truthy, not immediately obvious. There is also Enumerable#all? which works similarly (i.e. short circuit) but will evaluate the block as criterion: irb(main):010:0> e = [1,2,3] => [1, 2, 3] irb(main):011:0> e.all? {|x| x > 0} => true irb(main):012:0> e.all? {|x| p x; x > 0} 1 2 3 => true irb(main):013:0> e.all? {|x| x > 1} => false irb(main):014:0> e.all? {|x| p x; x > 1} 1 => false There's also Enumerable#any? which has OR logic. irb(main):018:0> e.any? {|x| p x;x > 1} 1 2 => true Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/