Permalink
Browse files

String#start_with? and String#end_with? are not needed for Ruby >= 1.…

…8.7, leaves their plural aliases though
  • Loading branch information...
1 parent 004db18 commit c0bb4c6ed2f5a5676569746e7bfd70405346ef8f @fxn fxn committed Nov 9, 2009
@@ -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 @@ def test_starts_ends_with_alias
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

0 comments on commit c0bb4c6

Please sign in to comment.