From: Benoit Daloze Date: 2011-11-01T23:01:59+09:00 Subject: [ruby-core:40630] [ruby-trunk - Bug #5536] String#start_with? and end_with? ignore arguments convertible to a String [PATCH] Issue #5536 has been updated by Benoit Daloze. > Issue #5536 has been updated by Nobuyoshi Nakada. > > (11/11/01 21:43), Benoit Daloze wrote: >> 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)? > > See test/ruby/test_m17n_comb.rb. Sorry, I missed it, I only looked at test/ruby/test_string.rb. But I'm not sure the error tests belong there, as test_m17n_comb.rb mainly focus on Encoding interactions. Should I add in test_string.rb or test_m17n_comb.rb? Here is the diff for test_m17n_comb.rb: diff --git a/test/ruby/test_m17n_comb.rb b/test/ruby/test_m17n_comb.rb index 79016af..9c6d5f3 100644 --- a/test/ruby/test_m17n_comb.rb +++ b/test/ruby/test_m17n_comb.rb @@ -1551,6 +1551,7 @@ class TestM17NComb < Test::Unit::TestCase end assert_equal(false, enccall(s1, :end_with?, s2), desc) } + assert_raise(TypeError) { "str".end_with? :not_convertible_to_string } end def test_str_start_with? @@ -1572,6 +1573,7 @@ class TestM17NComb < Test::Unit::TestCase end assert_equal(false, enccall(s1, :start_with?, s2), desc) } + assert_raise(TypeError) { "str".start_with? :not_convertible_to_string } end def test_str_ord ---------------------------------------- Bug #5536: String#start_with? and end_with? ignore arguments convertible to a String [PATCH] http://redmine.ruby-lang.org/issues/5536 Author: Benoit Daloze Status: Assigned Priority: Normal Assignee: 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://redmine.ruby-lang.org