aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/object.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/object/exclusion.rb15
2 files changed, 16 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb
index f4f9152d6a..a2c5a472f5 100644
--- a/activesupport/lib/active_support/core_ext/object.rb
+++ b/activesupport/lib/active_support/core_ext/object.rb
@@ -4,6 +4,7 @@ require 'active_support/core_ext/object/duplicable'
require 'active_support/core_ext/object/deep_dup'
require 'active_support/core_ext/object/try'
require 'active_support/core_ext/object/inclusion'
+require 'active_support/core_ext/object/exclusion'
require 'active_support/core_ext/object/conversions'
require 'active_support/core_ext/object/instance_variables'
diff --git a/activesupport/lib/active_support/core_ext/object/exclusion.rb b/activesupport/lib/active_support/core_ext/object/exclusion.rb
new file mode 100644
index 0000000000..58dfb649e5
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/object/exclusion.rb
@@ -0,0 +1,15 @@
+class Object
+ # Returns true if this object is excluded in the argument. Argument must be
+ # any object which responds to +#include?+. Usage:
+ #
+ # characters = ["Konata", "Kagami", "Tsukasa"]
+ # "MoshiMoshi".not_in?(characters) # => true
+ #
+ # This will throw an +ArgumentError+ if the argument doesn't respond
+ # to +#include?+.
+ def not_in?(another_object)
+ !another_object.include?(self)
+ rescue NoMethodError
+ raise ArgumentError.new("The parameter passed to #not_in? must respond to #include?")
+ end
+end \ No newline at end of file