String#start_with? and String#end_with? are not needed for Ruby >= 1.8.7, leaves their plural aliases though

This commit is contained in:
Xavier Noria
2009-11-09 21:35:43 +01:00
parent 004db18cb0
commit c0bb4c6ed2
2 changed files with 0 additions and 22 deletions

View File

@@ -1,18 +1,4 @@
class String
unless '1.8.7 and up'.respond_to?(:start_with?)
# Does the string start with the specified +prefix+?
def start_with?(prefix)
prefix = prefix.to_s
self[0, prefix.length] == prefix
end
# Does the string end with the specified +suffix+?
def end_with?(suffix)
suffix = suffix.to_s
self[-suffix.length, suffix.length] == suffix
end
end
alias_method :starts_with?, :start_with?
alias_method :ends_with?, :end_with?
end

View File

@@ -185,17 +185,9 @@ class StringInflectionsTest < Test::Unit::TestCase
assert s.starts_with?('hel')
assert !s.starts_with?('el')
assert s.start_with?('h')
assert s.start_with?('hel')
assert !s.start_with?('el')
assert s.ends_with?('o')
assert s.ends_with?('lo')
assert !s.ends_with?('el')
assert s.end_with?('o')
assert s.end_with?('lo')
assert !s.end_with?('el')
end
def test_string_squish