Skip to content

Commit

Permalink
ruby 1.8.7 compat: starts/ends_with? doesn't cast to string
Browse files Browse the repository at this point in the history
`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
mislav authored and jeremy committed Apr 16, 2010
1 parent 18ba648 commit c519215
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions activesupport/test/core_ext/string_ext_test.rb
Expand Up @@ -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')
Expand All @@ -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')
Expand Down

0 comments on commit c519215

Please sign in to comment.