From 19c48281a7bd94a42a80c1f8fc905e95820e8506 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 27 Dec 2009 15:49:29 -0800 Subject: String#exclude? core extension: inverse of #include? --- activesupport/lib/active_support/core_ext/string.rb | 3 ++- activesupport/lib/active_support/core_ext/string/exclude.rb | 6 ++++++ activesupport/test/core_ext/string_ext_test.rb | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 activesupport/lib/active_support/core_ext/string/exclude.rb (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/string.rb b/activesupport/lib/active_support/core_ext/string.rb index 0365b6af1c..411ea0f016 100644 --- a/activesupport/lib/active_support/core_ext/string.rb +++ b/activesupport/lib/active_support/core_ext/string.rb @@ -7,4 +7,5 @@ require 'active_support/core_ext/string/access' 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' \ No newline at end of file +require 'active_support/core_ext/string/output_safety' +require 'active_support/core_ext/string/exclude' diff --git a/activesupport/lib/active_support/core_ext/string/exclude.rb b/activesupport/lib/active_support/core_ext/string/exclude.rb new file mode 100644 index 0000000000..5ca268b953 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/string/exclude.rb @@ -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 diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 6ed209f724..9a805bc010 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -441,3 +441,10 @@ class OutputSafetyTest < ActiveSupport::TestCase 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 -- cgit v1.2.3