#many? uses count instead of select - a bit faster

This commit is contained in:
Julius Markūnas
2011-07-11 14:59:51 +03:00
parent e9f9ce971e
commit ea0eb02f48

View File

@@ -96,7 +96,7 @@ module Enumerable
# Returns true if the collection has more than 1 element. Functionally equivalent to collection.size > 1.
# Can be called with a block too, much like 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 = block_given? ? count(&block) : self.size
size > 1
end