Skip to content

Commit

Permalink
Added Enumberable#several? to encapsulate collection.size > 1 [DHH]
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Jun 12, 2008
1 parent ed0cb91 commit 556204a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 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]
Expand Down
5 changes: 5 additions & 0 deletions activesupport/lib/active_support/core_ext/enumerable.rb
Expand Up @@ -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
6 changes: 6 additions & 0 deletions activesupport/test/core_ext/enumerable_test.rb
Expand Up @@ -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

0 comments on commit 556204a

Please sign in to comment.