Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 556204abaf95f7c995576cb1358f13de406682ab 1 parent ed0cb91
@dhh dhh authored
View
2  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]
View
5 activesupport/lib/active_support/core_ext/enumerable.rb
@@ -66,4 +66,9 @@ def index_by
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
View
6 activesupport/test/core_ext/enumerable_test.rb
@@ -63,4 +63,10 @@ def test_index_by
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
Please sign in to comment.
Something went wrong with that request. Please try again.