1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add Enumerable#exclude? to bring parity to Enumerable#include? and avoid if !x.include?/else calls [DHH]

This commit is contained in:
David Heinemeier Hansson 2009-12-14 18:00:14 -08:00
parent 5f8e48cbd2
commit 7b61541ea5
3 changed files with 12 additions and 0 deletions

View file

@ -1,5 +1,7 @@
*Edge*
* Add Enumerable#exclude? to bring parity to Enumerable#include? and avoid if !x.include?/else calls [DHH]
* Update Edinburgh TimeZone to use "Europe/London" instead of "Europe/Dublin" #3310 [Phil Ross]
* Update bundled TZInfo to v0.3.15 [Geoff Buesing]

View file

@ -101,6 +101,11 @@ module Enumerable
size = block_given? ? select(&block).size : self.size
size > 1
end
# The negative of the Enumerable#include?. Returns true if the collection does not include the object.
def exclude?(object)
!include?(object)
end
end
class Range #:nodoc:

View file

@ -89,4 +89,9 @@ class EnumerableTests < Test::Unit::TestCase
assert ![ 1, 2 ].many? {|x| x > 1 }
assert [ 1, 2, 2 ].many? {|x| x > 1 }
end
def test_exclude?
assert [ 1 ].exclude?(2)
assert ![ 1 ].exclude?(1)
end
end