Permalink
Browse files

String#exclude? core extension: inverse of #include?

  • Loading branch information...
1 parent 7c4fb93 commit 19c48281a7bd94a42a80c1f8fc905e95820e8506 @jeremy jeremy committed Dec 27, 2009
@@ -7,4 +7,5 @@
require 'active_support/core_ext/string/xchar'
require 'active_support/core_ext/string/behavior'
require 'active_support/core_ext/string/interpolation'
-require 'active_support/core_ext/string/output_safety'
+require 'active_support/core_ext/string/output_safety'
+require 'active_support/core_ext/string/exclude'
@@ -0,0 +1,6 @@
+class String
+ # The inverse of String#include?. Returns true if the string does not include the other string.
+ def exclude?(string)
+ !include?(string)
+ end
+end
@@ -441,3 +441,10 @@ def to_str
assert @string.html_safe?
end
end
+
+class StringExcludeTest < ActiveSupport::TestCase
+ test 'inverse of #include' do
+ assert_equal false, 'foo'.exclude?('o')
+ assert_equal true, 'foo'.exclude?('p')
+ end
+end

0 comments on commit 19c4828

Please sign in to comment.