-1

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.

  • 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
  • 1
    Thank 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 Answers1

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