mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Add Enumerable#exclude? to bring parity to Enumerable#include? and avoid if !x.include?/else calls [DHH]
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user