Ruby Tips

Pattern-Matching Operator

=~ is Ruby's basic pattern-matching operator. If a match is found, the operator returns index of first match in string, otherwise it returns nil.

/john/ =~ 'john'  #=> 0

/mike/ =~ 'john'  #=> nil

Ruby Tips - a simple ruby tip generator RubyTips.dev

Refresh the page to generate a new tip. Or just click here

Built by @zayneabraham

RubyTips - A random Ruby tip generator | Product Hunt Embed