我有一个较长的字符串变量,想要确定它是否包含两个子字符串中的任意一个。
例如:
例如:
haystack = 'this one is pretty long'
needle1 = 'whatever'
needle2 = 'pretty'
现在我需要这样的一个析取式,尽管在Ruby中不起作用:
if haystack.include? needle1 || haystack.include? needle2
puts "needle found within haystack"
end
needles = [obj1, obj2, ..., objN]; needles.any? { |needle| haystack.include? needle }
- daybreaker