Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

[#3199 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit c519215aa83b041d438772977f962f54fff81a83 1 parent 18ba648
Mislav Marohnić mislav authored jeremy committed
4 activesupport/lib/active_support/core_ext/string/starts_ends_with.rb
View
@@ -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
2  activesupport/test/core_ext/string_ext_test.rb
View
@@ -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')
Please sign in to comment.
Something went wrong with that request. Please try again.