Here is my code:
>> x = "apple spoon"
=> "apple spoon"
>> y = "spoon tree"
=> "spoon tree"
>> z = "apple tree"
=> "apple tree"
>> puts "match" if x.upcase.match("APPLE" && "SPOON" && "TREE")
=> nil
>> puts "match" if y.upcase.match("APPLE" && "SPOON" && "TREE")
match
=> nil
>> puts "match" if z.upcase.match("APPLE" && "SPOON" && "TREE")
match
=> nil
What I expected to have happen is not get any matches at all. Why do I get matches on y and z?
As dmarkow says, the && operator is for boolean operations, not to give multiple arguments to match().
If you need to find if it matches any of the strings, use some sort of iterator, such as:
Also, since String#match accepts a regular expression, I think you can do a case insensitive regex:
or you could:
and since you said you wanted to match all terms:
If the regex confuses you and you want to upcase first: