Skip to content

Commit

Permalink
String#starts/ends_with? should return false for non-string argumen…
Browse files Browse the repository at this point in the history
…t, not raise error

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
mislav authored and jeremy committed Apr 17, 2010
1 parent c55cdd8 commit 4b36daf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def self.append_features(base)

# Does the string start with the specified +prefix+?
def starts_with?(prefix)
self[0, prefix.length] == prefix
prefix.respond_to?(:to_str) && self[0, prefix.length] == prefix
end

# Does the string end with the specified +suffix+?
def ends_with?(suffix)
self[-suffix.length, suffix.length] == suffix
suffix.respond_to?(:to_str) && self[-suffix.length, suffix.length] == suffix
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions activesupport/test/core_ext/string_ext_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +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) if :hel.respond_to?(:length)
assert !s.starts_with?(:hel)
assert !s.starts_with?('el')

assert s.start_with?('h')
Expand All @@ -186,7 +186,7 @@ def test_starts_ends_with_alias

assert s.ends_with?('o')
assert s.ends_with?('lo')
assert !s.ends_with?(:lo) if :lo.respond_to?(:length)
assert !s.ends_with?(:lo)
assert !s.ends_with?('el')

assert s.end_with?('o')
Expand Down

0 comments on commit 4b36daf

Please sign in to comment.