From 161ab28b7c0bd28828b6d18613a9de09d47023c6 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 20 Jun 2008 11:31:06 -0500 Subject: Added block-handling to Enumerable#many? (Damian Janowski) [#452 state:resolved] --- activesupport/lib/active_support/core_ext/enumerable.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index 9647797ec2..e451e9933a 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -79,7 +79,9 @@ module Enumerable end # Returns true if the collection has more than 1 element. Functionally equivalent to collection.size > 1. - def many? + # Works with a block too ala any?, so people.many? { |p| p.age > 26 } # => returns true if more than 1 person is over 26. + def many?(&block) + size = block_given? ? select(&block).size : self.size size > 1 end end -- cgit v1.2.3