Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 895
sawa Avatar asked Jan 11 '16 10:01

sawa


People also ask

What is the use of @?

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].

Why do we use these symbols ♀ ♂?

♂️ 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.

What is the@ symbol called?

The at sign, @, is normally read aloud as "at"; it is also commonly called the at symbol, commercial at, or address sign.


1 Answers

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.

like image 53
sawa Avatar answered Oct 14 '22 05:10

sawa