[ruby-core:72872] [Ruby trunk - Bug #11991] `Symbol#match` returns the match position, unlike `String#match` and `Regexp#match`

From: eregontp@...
Date: 2016-01-15 09:43:42 UTC
List: ruby-core #72872
Issue #11991 has been updated by Benoit Daloze.


I would be happy to adapt the spec suite to the newer behavior if we decide so, of course.
However, I think such a change should be done not before the next minor (2.4) for potential incompatibility.

----------------------------------------
Bug #11991: `Symbol#match` returns the match position, unlike `String#match` and `Regexp#match`
https://bugs.ruby-lang.org/issues/11991#change-56105

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
`String#match` and `Regexp#match` return a `MatchData` when match succeeds:

~~~RUBY
"".match(//) # => #<MatchData "">
//.match("") # => #<MatchData "">
//.match(:"") # => #<MatchData "">
~~~

But `Symbol#match` returns the match position (like `String#=~`):

~~~RUBY
:"".match(//) # => 0
~~~

Thus, `Symbol#match` behaves differently from `String#match` and `Regexp#match`. This is the documented behavior, but it may be a bug (together with the documentation).

On the other hand, if it is not a bug, what is the rationale?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next