From 9cf9e44a4bc5bcb0eade8f2772ed3c61e02d680e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 14 Sep 2009 15:44:42 +0200 Subject: [PATCH] ruby 1.8.7 compat: `starts/ends_with?` doesn't cast to string `starts/ends_with?` methods shouldn't cast argument to string because ruby 1.8.7 doesn't seem to do that. for example: "foobar".ends_with?(:bar) # => true in ActiveSupport implementation, false in ruby 1.8.7 --- .../core_ext/string/starts_ends_with.rb | 4 +--- activesupport/test/core_ext/string_ext_test.rb | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) 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 09f9a18..bd4f39d 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 @@ module ActiveSupport #:nodoc: # 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 2325103..084f861 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -177,6 +177,7 @@ class StringInflectionsTest < Test::Unit::TestCase 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 @@ class StringInflectionsTest < Test::Unit::TestCase 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') -- 1.7.0.4