Skip to content
This repository
Browse code

Added Enumberable#several? to encapsulate collection.size > 1 [DHH]

  • Loading branch information...
commit 556204abaf95f7c995576cb1358f13de406682ab 1 parent ed0cb91
David Heinemeier Hansson authored June 12, 2008
2  activesupport/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *Edge*
2 2
 
  3
+* Added Enumberable#several? to encapsulate collection.size > 1 [DHH]
  4
+
3 5
 * Add more standard Hash methods to ActiveSupport::OrderedHash [Steve Purcell]
4 6
 
5 7
 * Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under ActiveSupport [Josh Peek]
5  activesupport/lib/active_support/core_ext/enumerable.rb
@@ -66,4 +66,9 @@ def index_by
66 66
       accum
67 67
     end
68 68
   end
  69
+  
  70
+  # Returns true if the collection has more than 1 element. Functionally equivalent to collection.size > 1.
  71
+  def several?
  72
+    size > 1
  73
+  end
69 74
 end
6  activesupport/test/core_ext/enumerable_test.rb
@@ -63,4 +63,10 @@ def test_index_by
63 63
     assert_equal({ 5 => payments[0], 15 => payments[1], 10 => payments[2] },
64 64
                  payments.index_by { |p| p.price })
65 65
   end
  66
+  
  67
+  def test_several
  68
+    assert ![].several?
  69
+    assert ![ 1 ].several?
  70
+    assert [ 1, 2 ].several?
  71
+  end
66 72
 end

0 notes on commit 556204a

Please sign in to comment.
Something went wrong with that request. Please try again.