From: WATANABE Hirofumi Date: 2002-11-28T02:41:15+09:00 Subject: Re: Array#and? and Array#or? methods? Jeff de Vries writes: > > Is there some reason the following methods on Array aren't included as > standard? > > class Array > def and? > # return true if the provided block returns true for every element > each {|x| return false unless yield x} if block_given? > return true > end > def or? > # return true if the provided block returns true for at least one > element > each {|x| return true if yield x} if block_given? > return false > end > end > > I find these to be very useful, and was suprised to not see them. Is > there another way to get the same effect (including short circuit of > evaluation as soon as a condition fails)? Ruby 1.7 has Enumerable#all? and Enumerable#any? . -- eban