Use .many? to Determine if Collection has > 1 recs
Today I learned about many?, which is a convenience method in ActiveSupport for determining if there is more than one record present. It's similar to any?, but the key difference is many? is strictly greater than, whereas any? is greater than or equal to.
-
any?returns true if >= 1 record -
many?returns true if > 1 record.
many? is available on ActiveRecord::Relation and Enumerable (via ActiveSupport). When used on Enumerable it can be passed a block (similar to any?).
people.many? { |p| p.age > 26 }
Tweet