aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/object/inclusion.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/object/inclusion.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/object/inclusion.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/inclusion.rb b/activesupport/lib/active_support/core_ext/object/inclusion.rb
new file mode 100644
index 0000000000..79e9fd6c88
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/object/inclusion.rb
@@ -0,0 +1,20 @@
+class Object
+ # Returns true if this object is included in the argument. Argument must be
+ # any object which respond to +#include?+. Usage:
+ #
+ # characters = ["Konata", "Kagami", "Tsukasa"]
+ # "Konata".in?(characters) # => true
+ #
+ def in?(another_object)
+ another_object.include?(self)
+ end
+
+ # Returns true if this object is included in the argument list. Usage:
+ #
+ # username = "sikachu"
+ # username.either?("josevalim", "dhh", "wycats") # => false
+ #
+ def either?(*objects)
+ objects.include?(self)
+ end
+end