Alex Rivera | Logout

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

Asked 2012-04-22T18:32:02.970
9

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

Edit
Report

1 Answer

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

See: Enumerable#include?

answered 2012-04-22T18:35:23.297

Your Answer