mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user