[ Why does `Symbol#match` behave differently from `String#match` and `Regexp#match`? ]
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
Why does Symbol#match
behave differently? Is there a use case?
Answer 1
I reported it as a bug in Ruby core: https://bugs.ruby-lang.org/issues/11991. Let's see what they will say.
Update
The questioned behaviour seems to have been a bug. It seems that from Ruby 2.4, Symbol#match
will return a MatchData
instance when a match succeeds.