Reputation: 11091
What is the simpler way of below ruby condition? What can I use instead of two include?
str1="str"
str2="sss"
string='string'
puts "yes" if (string.include?(str1) or string.include?(str2))
Upvotes: 0
Views: 80
Reputation: 54984
You can just do:
puts "yes" if string[str1] || string[str2]
But how about:
puts "yes" if [str1,str2].any?{|s| string[s]}
or even:
puts "yes" if string[/#{str1}|#{str2}/]
Upvotes: 3