From: "Eregon (Benoit Daloze)" Date: 2013-01-31T01:19:04+09:00 Subject: [ruby-core:51760] [ruby-trunk - Bug #5536] String#start_with? and end_with? ignore arguments convertible to a String [PATCH] Issue #5536 has been updated by Eregon (Benoit Daloze). prijutme4ty (Ilya Vorontsov) wrote: > =begin > Can you please explain, why not just make (({"str".start_with(/s/)})) behave as (({"str".match(/^s/)})) ? > =end See #3388 for this feature (this issue is closed). It is the approach I initially took, but building and compiling a Regexp is expensive, and so it should be cached or another way be used. For #start_with?, there is a C-level API for matching only at start, but there is no corresponding API for #end_with?. ---------------------------------------- Bug #5536: String#start_with? and end_with? ignore arguments convertible to a String [PATCH] https://bugs.ruby-lang.org/issues/5536#change-35731 Author: Eregon (Benoit Daloze) Status: Closed Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: 2.0.0 ruby -v: ruby 2.0.0dev (2011-11-01 trunk 33605) [x86_64-linux] 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)? -- http://bugs.ruby-lang.org/