Added String#starts_with? and String#ends_with? #2118 [thijs@vandervossen.net]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2171 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 afbfde93
*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|
......
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
......@@ -81,4 +81,15 @@ def test_access
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册