Project

General

Profile

Feature #12898

String#match? method in addition to Regexp#match?

Added by sos4nt (Stefan Schüßler) about 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:77908]

Description

Ruby 2.4 introduces Regexp#match?. There should be an accompanying String#match? method.

Associated revisions

Revision 6dd5ee75
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

String#match? and Symbol#match?

  • string.c (rb_str_match_m_p): inverse of Regexp#match?. based on the patch by Herwin Weststrate herwin@snt.utwente.nl. [Fix GH-1483] [Feature #12898]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 57053
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

String#match? and Symbol#match?

  • string.c (rb_str_match_m_p): inverse of Regexp#match?. based on the patch by Herwin Weststrate herwin@snt.utwente.nl. [Fix GH-1483] [Feature #12898]

Revision 57053
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

String#match? and Symbol#match?

  • string.c (rb_str_match_m_p): inverse of Regexp#match?. based on the patch by Herwin Weststrate herwin@snt.utwente.nl. [Fix GH-1483] [Feature #12898]

Revision 57053
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

String#match? and Symbol#match?

  • string.c (rb_str_match_m_p): inverse of Regexp#match?. based on the patch by Herwin Weststrate herwin@snt.utwente.nl. [Fix GH-1483] [Feature #12898]

Revision 57053
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

String#match? and Symbol#match?

  • string.c (rb_str_match_m_p): inverse of Regexp#match?. based on the patch by Herwin Weststrate herwin@snt.utwente.nl. [Fix GH-1483] [Feature #12898]

Revision 9f379854
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

test for Symbol#match? [Feature #12898]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 57055
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

test for Symbol#match? [Feature #12898]

Revision 57055
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

test for Symbol#match? [Feature #12898]

Revision 57055
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

test for Symbol#match? [Feature #12898]

Revision 57055
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

test for Symbol#match? [Feature #12898]

History

Updated by shyouhei (Shyouhei Urabe) about 3 years ago

Stefan Schüßler wrote:

Ruby 2.4 introduces Regexp#match?. There should be an accompanying String#match? method.

Can you be a bit more verbose here? You mean a String instance method named "match?" that takes a Regexp instance? Please show us in detail why you need that.

Updated by sos4nt (Stefan Schüßler) about 3 years ago

Shyouhei Urabe wrote:

You mean a String instance method named "match?" that takes a Regexp instance?

Yes, exactly. The methods to match a string with a regexp (or vice versa) are present in both classes:

Regexp#=~ and String#=~
Regexp#match and String#match

With Ruby 2.4 there's Regexp#match? and it would only be consistent to implement String#match? as well.

I would expect String#match? to work equivalent to String#=~ and String#match, i.e.

str.match?(pattern) -> true or false
str.match?(pattern,pos) -> true or false
Converts pattern to a Regexp (if it isn’t already one), then invokes its match? method on str.
Returns a (...)

Updated by herwin (Herwin W) about 3 years ago

I just opened a pull request to add this behaviour: https://github.com/ruby/ruby/pull/1483

It surprised me that his behaviour wasn't implemented.

#5

Updated by nobu (Nobuyoshi Nakada) almost 3 years ago

  • Status changed from Open to Closed

Applied in changeset r57053.


String#match? and Symbol#match?

  • string.c (rb_str_match_m_p): inverse of Regexp#match?. based on the patch by Herwin Weststrate herwin@snt.utwente.nl. [Fix GH-1483] [Feature #12898]

Also available in: Atom PDF