[ruby-core:121692] [Ruby Feature#3388] regexp support for start_with? and end_with?

Issue #3388 has been updated by baweaver (Brandon Weaver). I have admittedly found this confusing recently when I had attempted to use `end_with?(/regex/)` in a book example. Would it be acceptable to consider a non-ideal implementation of this feature, and then continue to optimize it in future releases? I believe the potential confusion relative to its dual method `start_with?` warrants some consideration of consistency in implementation here, even if not enough distinct cases exist exclusively for `end_with?` and regular expressions. ---------------------------------------- Feature #3388: regexp support for start_with? and end_with? https://bugs.ruby-lang.org/issues/3388#change-112743 * Author: trans (Thomas Sawyer) * Status: Feedback * Assignee: naruse (Yui NARUSE) ---------------------------------------- =begin ruby-1.9.2-head > "aBcdeFghIj".start_with?(/abc/i) => false In my implementation of start_with? it is easy enough to utilize #index, which works fine: def start_with?(pattern) index(pattern) == 0 end But #end_with? is more difficult, and I had to use regular expressions. def end_with?(suffix) suffix = Regexp.escape(suffix) if String===suffix /#{suffix}$/.match(self) ? true : false end However, we might get rid of the '? true : false' and return the MatchData, since that could be useful information. =end ---Files-------------------------------- 0001-string.c-rb_str_start_with-rb_str_end_with-allow-Reg.patch (4.08 KB) -- https://bugs.ruby-lang.org/
participants (1)
-
baweaver (Brandon Weaver)