diff --git a/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb b/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb index 09f9a188b51ed..bd4f39dd4a982 100644 --- a/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb +++ b/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb @@ -20,14 +20,12 @@ def self.append_features(base) # Does the string start with the specified +prefix+? def starts_with?(prefix) - prefix = prefix.to_s self[0, prefix.length] == prefix end # Does the string end with the specified +suffix+? def ends_with?(suffix) - suffix = suffix.to_s - self[-suffix.length, suffix.length] == suffix + self[-suffix.length, suffix.length] == suffix end end end diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 23251035dc784..084f8611bfaa8 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -177,6 +177,7 @@ def test_starts_ends_with_alias s = "hello" assert s.starts_with?('h') assert s.starts_with?('hel') + assert !s.starts_with?(:hel) assert !s.starts_with?('el') assert s.start_with?('h') @@ -185,6 +186,7 @@ def test_starts_ends_with_alias assert s.ends_with?('o') assert s.ends_with?('lo') + assert !s.ends_with?(:lo) assert !s.ends_with?('el') assert s.end_with?('o')