I found this operator by chance:
ruby-1.9.2-p290 :028 > "abc" !=~ /abc/
=> true
what’s this? It’s behavior doesn’t look like “not match”.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That’s not one operator, that’s two operators written to look like one operator.
From the operator precedence table (highest to lowest):
Also, the Regexp class has a unary
~operator:So your expression is equivalent to:
And the
Regexp#=~operator (not the same as the more familiarString#=~) returns a number:So you get true as your final result because comparing a string to a number is false.
For example: