Project

General

Profile

Actions

Bug #5536

closed

String#start_with? and end_with? ignore arguments convertible to a String [PATCH]

Added by Eregon (Benoit Daloze) about 13 years ago. Updated almost 12 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 2.0.0dev (2011-11-01 trunk 33605) [x86_64-linux]
Backport:
[ruby-core:40623]

Description

Hi,

Currently, String#start_with? and String#end_with? ignore arguments not convertible to String.

I believe it should instead raise an error,
as it may lead to false expectations from the user and
it is inconsistent with the rest of the API.

For example, if I try to use start_with? with a RegExp (which would be a nice feature BTW):
"str".start_with? /s/ # => false
I believe it should be:
"str".start_with? /s/ # => TypeError: can't convert Regexp into String

If you prefer the current behavior, could you explain me why?

P.S.: There is no test for String#{start,end}_with? in test/, should I add one or is it enough to change RubySpec (which I'll do when this gets accepted)?


Files


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Feature #3388: regexp support for start_with? and end_with?Feedbacknaruse (Yui NARUSE)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0