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

From: naruse@...
Date: 2016-02-16 09:18:12 UTC
List: ruby-core #73833
Issue #11991 has been updated by Yui NARUSE.

Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.0.0: WONTFIX, 2.1: WONTFIX, 2.2: WONTFIX, 2.3: WONTFIX

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

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.0.0: WONTFIX, 2.1: WONTFIX, 2.2: WONTFIX, 2.3: WONTFIX
----------------------------------------
`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