Is there a method that let me compare one String with multiple others in Ruby? I really would like to do something like this:
myString.eql?(["string1","string2","string3"])
Is there a method that let me compare one String with multiple others in Ruby? I really would like to do something like this:
myString.eql?(["string1","string2","string3"])
You could use Array#include?
to see if the array includes the string:
%w(string1 string2 string3).include?(myString)
I find myself wanting this a lot, so I added a String method to be able to do it more idiomatically:
class String
def among?(*array)
array.flatten.include?(self)
end
end
Then
myString.among?("string1","string2","string3")