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

This commit is contained in:
David Heinemeier Hansson 2008-06-12 17:46:15 -05:00
parent ed0cb91a83
commit 556204abaf
3 changed files with 13 additions and 0 deletions

View File

@ -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 File

@ -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

View File

@ -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