Hello,
I'm just starting off with Ruby, but I have a task that landed on my desk that I need a quick answer for, and haven't been able to find a solution online. I appreciate any help I can get.
I need to know if a value in one array appears in another. This should be easy enough with a loop but I'm looking to do it the "Ruby way", if there's such a thing. Here's my current code:
TARGET_COLOR = "red"
# product.color contains "orange, yellow, red", for example
if product.color.any? { |string| string.include?(TARGET_COLOR) }
#do stuff
Now if I change the first line to TARGET_COLOR = ["red", "green"]
, I get an error -- I'm guessing the .include?
accepts only strings.
What would be the correct syntax/method to search TARGET_COLOR?