Skip to content
This repository
Browse code

Added String#starts_with? and String#ends_with? #2118 [thijs@vandervo…

…ssen.net]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2171 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 74896c0252bf76c159a40895a5dfe2e75ab112bf 1 parent afbfde9
David Heinemeier Hansson authored September 09, 2005
2  activesupport/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Added String#starts_with? and String#ends_with? #2118 [thijs@vandervossen.net]
  4
+
3 5
 * Added easy extendability to the inflector through Inflector.inflections (using the Inflector::Inflections singleton class). Examples:
4 6
 
5 7
     Inflector.inflections do |inflect|
2  activesupport/lib/active_support/core_ext/string.rb
... ...
@@ -1,9 +1,11 @@
1 1
 require File.dirname(__FILE__) + '/string/inflections'
2 2
 require File.dirname(__FILE__) + '/string/conversions'
3 3
 require File.dirname(__FILE__) + '/string/access'
  4
+require File.dirname(__FILE__) + '/string/starts_ends_with'
4 5
 
5 6
 class String #:nodoc:
6 7
   include ActiveSupport::CoreExtensions::String::Access
7 8
   include ActiveSupport::CoreExtensions::String::Conversions
8 9
   include ActiveSupport::CoreExtensions::String::Inflections
  10
+  include ActiveSupport::CoreExtensions::String::StartsEndsWith
9 11
 end
11  activesupport/test/core_ext/string_ext_test.rb
@@ -81,4 +81,15 @@ def test_access
81 81
     assert_equal "o", s.last
82 82
     assert_equal "llo", s.last(3)
83 83
   end
  84
+
  85
+  def test_starts_ends_with
  86
+    s = "hello"    
  87
+    assert s.starts_with?('h')    
  88
+    assert s.starts_with?('hel')    
  89
+    assert !s.starts_with?('el')    
  90
+
  91
+    assert s.ends_with?('o')    
  92
+    assert s.ends_with?('lo')    
  93
+    assert !s.ends_with?('el')  
  94
+  end
84 95
 end

0 notes on commit 74896c0

Please sign in to comment.
Something went wrong with that request. Please try again.