Project

General

Profile

Actions

Bug #11991

closed

`Symbol#match` returns the match position, unlike `String#match` and `Regexp#match`

Bug #11991: `Symbol#match` returns the match position, unlike `String#match` and `Regexp#match`

Added by sawa (Tsuyoshi Sawada) almost 10 years ago. Updated almost 10 years ago.


Description

String#match and Regexp#match return a MatchData when match succeeds:

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

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

:"".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?

Actions

Also available in: PDF Atom