I was wondering if anyone could explain what the =~
operator does in Ruby. I have seen it a few times but am unable to find a proper explanation of it.
Asked
Active
Viewed 177 times
-1

Sai Dandamudi
- 83
- 7
-
Duplicate of http://stackoverflow.com/questions/12992065/meaning-of-in-ruby – Slate Nov 18 '13 at 23:45
-
Hey meagar, do you know whats the name of the search engine that can search symbols like these? I used to know it but of course i forgot. – Zippie Nov 18 '13 at 23:45
-
1@Zippie http://symbolhound.com – tckmn Nov 18 '13 at 23:50
-
1Thank you, although i think its not the one i was looking for. Guess i could have also used google :) – Zippie Nov 18 '13 at 23:51
-
1@Zippie: You can go to http://ruby-doc.org/core and type the operator into the *Methods* search and you'll find it. – mu is too short Nov 19 '13 at 00:39
-
1@Zippie Google "ruby operators", get exhaustive list. Notice **[ruby operator "=~" - Stack Overflow](http://stackoverflow.com/questions/5781362/ruby-operator)** is the 5th result. No symbols required. Also, if you don't `@user`, they won't see your comments. – user229044 Nov 19 '13 at 01:28
1 Answers
1
It is used to match Regexes against strings:
http://www.ruby-doc.org/core-2.0.0/Regexp.html#method-i-3D-7E
It returns either a Integer value of the first occurrence in the string or if the expression doesn't match the String it returns nil
.

Zippie
- 6,018
- 6
- 31
- 46
-
1Thanks for responding constructively instead of just making me feel bad for not finding it in my search – Sai Dandamudi Nov 19 '13 at 00:31