diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-07-22 19:48:46 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-22 19:48:46 -0300 |
commit | 0020f1a4c96731a17ac4f84fa67058b5bc459fe2 (patch) | |
tree | 18c4b17a50e004d6506755dd2730b6428f037cec /activesupport/lib/active_support/core_ext/object/exclusion.rb | |
parent | 92c60f87a6cbbe8c556399f415772c2dd2d48981 (diff) | |
parent | 4db6ac29f24f3d38401f4cf243a7a70b07e964e1 (diff) | |
download | rails-0020f1a4c96731a17ac4f84fa67058b5bc459fe2.tar.gz rails-0020f1a4c96731a17ac4f84fa67058b5bc459fe2.tar.bz2 rails-0020f1a4c96731a17ac4f84fa67058b5bc459fe2.zip |
Merge pull request #25914 from jmccartie/jm/not_in
Adds `not_in?` onto Object
Diffstat (limited to 'activesupport/lib/active_support/core_ext/object/exclusion.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/exclusion.rb | 15 |
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 |