Radek
Radek

Reputation: 11091

What to use instead of two include?'s?

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

Answers (1)

pguardiario
pguardiario

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

Related Questions