diff options
author | Jon McCartie <jon@mccartie.com> | 2016-07-21 16:47:27 -0500 |
---|---|---|
committer | Jon McCartie <jon@mccartie.com> | 2016-07-21 17:23:33 -0500 |
commit | 4db6ac29f24f3d38401f4cf243a7a70b07e964e1 (patch) | |
tree | 4002a2a48636c39a7bb431f4a31e816e1be0fe95 /activesupport/lib/active_support/core_ext/object/exclusion.rb | |
parent | 929a6500806fe671d9ac0002da8537bf26b8f25d (diff) | |
download | rails-4db6ac29f24f3d38401f4cf243a7a70b07e964e1.tar.gz rails-4db6ac29f24f3d38401f4cf243a7a70b07e964e1.tar.bz2 rails-4db6ac29f24f3d38401f4cf243a7a70b07e964e1.zip |
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 |