aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2009-12-14 18:00:14 -0800
committerDavid Heinemeier Hansson <david@loudthinking.com>2009-12-14 18:00:14 -0800
commit7b61541ea53c309847753d5553baa2eed9cc6282 (patch)
tree2440938485241d03c37757768987a76490376afd /activesupport/lib/active_support/core_ext
parent5f8e48cbd297aca4add4b48efa2136ba6ac851b1 (diff)
downloadrails-7b61541ea53c309847753d5553baa2eed9cc6282.tar.gz
rails-7b61541ea53c309847753d5553baa2eed9cc6282.tar.bz2
rails-7b61541ea53c309847753d5553baa2eed9cc6282.zip
Add Enumerable#exclude? to bring parity to Enumerable#include? and avoid if !x.include?/else calls [DHH]
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/enumerable.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb
index b11c916f61..d0821a7c68 100644
--- a/activesupport/lib/active_support/core_ext/enumerable.rb
+++ b/activesupport/lib/active_support/core_ext/enumerable.rb
@@ -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: