Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby does string equal one of the strings in an array of strings?

Is there an easy way to sort of call something similar to the database In query?

Does "mystring" exist in ["string1","mystring","string2"] => would return true

Does "mystring" exist in ["string1","string2","string3"] => would return false

like image 459
RailsTweeter Avatar asked Apr 22 '12 18:04

RailsTweeter


1 Answers

["string1","mystring","string2"].include? "mystring"

See: Enumerable#include?

like image 91
DigitalRoss Avatar answered Oct 01 '22 03:10

DigitalRoss