The `=~` operator

suggest change
if /hay/ =~ 'haystack'
  puts "There is hay in the word haystack"
end

Note: The order is significant. Though 'haystack' =~ /hay/ is in most cases an equivalent, side effects might differ:

=~ does not return true or false. It returns the index of the match, or nil if there is no match. Every integer is truthy in Ruby, including 0, and nil is falsy, so the result works in if. For a boolean, use ===, as in another example.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents