aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/core_ext/string.rb2
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb11
3 files changed, 15 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 99cbafe0a6..c4eed21534 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added String#starts_with? and String#ends_with? #2118 [thijs@vandervossen.net]
+
* Added easy extendability to the inflector through Inflector.inflections (using the Inflector::Inflections singleton class). Examples:
Inflector.inflections do |inflect|
diff --git a/activesupport/lib/active_support/core_ext/string.rb b/activesupport/lib/active_support/core_ext/string.rb
index fce0557c64..979f8a0515 100644
--- a/activesupport/lib/active_support/core_ext/string.rb
+++ b/activesupport/lib/active_support/core_ext/string.rb
@@ -1,9 +1,11 @@
require File.dirname(__FILE__) + '/string/inflections'
require File.dirname(__FILE__) + '/string/conversions'
require File.dirname(__FILE__) + '/string/access'
+require File.dirname(__FILE__) + '/string/starts_ends_with'
class String #:nodoc:
include ActiveSupport::CoreExtensions::String::Access
include ActiveSupport::CoreExtensions::String::Conversions
include ActiveSupport::CoreExtensions::String::Inflections
+ include ActiveSupport::CoreExtensions::String::StartsEndsWith
end
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index 34d4057cf9..c1c1918817 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -81,4 +81,15 @@ class StringInflectionsTest < Test::Unit::TestCase
assert_equal "o", s.last
assert_equal "llo", s.last(3)
end
+
+ def test_starts_ends_with
+ s = "hello"
+ assert s.starts_with?('h')
+ assert s.starts_with?('hel')
+ assert !s.starts_with?('el')
+
+ assert s.ends_with?('o')
+ assert s.ends_with?('lo')
+ assert !s.ends_with?('el')
+ end
end