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 | |
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')
-rw-r--r-- | activesupport/lib/active_support/core_ext/object.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/exclusion.rb | 15 |
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 |