aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/object
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/object')
-rw-r--r--activesupport/lib/active_support/core_ext/object/exclusion.rb15
1 files changed, 15 insertions, 0 deletions
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