SupremeA SupremeA - 1 year ago 60
Ruby Question

Check if a string is any of multiple items

I have a string

x = "student"

how do I check if "x" matches any of the items in a list of names that I have. The names are a fixed list.

names = ["teacher",

I tried setting names as a list and using any? to check the list but that seems to only work for an array and I have a string.

I am using Ruby 2.2.1 Also I only need it to return true or false if the item is in the list

Answer Source

If the string is inside the array it will return true

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download