diff options
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/enumerable.rb | 5 | ||||
-rw-r--r-- | activesupport/test/core_ext/enumerable_test.rb | 6 |
3 files changed, 13 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index c7739fd7e0..b72f638d82 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *Edge* +* Added Enumberable#several? to encapsulate collection.size > 1 [DHH] + * Add more standard Hash methods to ActiveSupport::OrderedHash [Steve Purcell] * Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under ActiveSupport [Josh Peek] diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index f1469aa0e3..47ff19e963 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -66,4 +66,9 @@ module Enumerable accum end end + + # Returns true if the collection has more than 1 element. Functionally equivalent to collection.size > 1. + def several? + size > 1 + end end diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index f5facd54ad..c37e0d269e 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -63,4 +63,10 @@ class EnumerableTests < Test::Unit::TestCase assert_equal({ 5 => payments[0], 15 => payments[1], 10 => payments[2] }, payments.index_by { |p| p.price }) end + + def test_several + assert ![].several? + assert ![ 1 ].several? + assert [ 1, 2 ].several? + end end |