I assume there is a nice one-line way to say in ruby
if mystr == "abc" or "def " or "ghi" or "xyz"
but cannot find how to do that in the online references I normally consult…
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Perhaps you didn’t know that you can put multiple conditions on a single case:
But for this specific string-based test, I would use regex:
If you don’t want to construct a regex, and you don’t want a
casestatement, you can create an array of objects and useArray#include?test to see if the object is in the array:or, by monkey-patching Object, you can even turn it around: