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?
On the Internet, @ (pronounced "at" or "at sign" or "address sign") is the symbol in an E-mail address that separates the name of the user from the user's Internet address, as in this hypothetical e-mail address example: [email protected].
♂️ and ♀️ are defined as "gender identity symbols" because they are commonly used to denote the sex of all forms of life, they are part of the universal symbol system because they are widely spread and are recognized worldwide.
The at sign, @, is normally read aloud as "at"; it is also commonly called the at symbol, commercial at, or address sign.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With