Check whether a string contains one of multiple substrings

Solution 1:

[needle1, needle2].any? { |needle| haystack.include? needle }

Solution 2:

Try parens in the expression:

 haystack.include?(needle1) || haystack.include?(needle2)

Solution 3:

You can do a regex match:

haystack.match? /needle1|needle2/

Or if your needles are in an array:

haystack.match? Regexp.union(needles)

(For Ruby < 2.4, use .match without question mark.)

Solution 4:

(haystack.split & [needle1, needle2]).any?

To use comma as separator: split(',')