Project

General

Profile

Actions

Bug #11991

closed

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

Added by sawa (Tsuyoshi Sawada) over 8 years ago. Updated about 8 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: Atom PDF

Like0
Like0Like0Like0Like0Like0