ruby - How to do if X is equal to either one of these values (xxx,eeee,yyyy,dadadad) -
this question has answer here:
example if fileext "doc"
if fileext equal either ("doc", "xls", "ppt")
any ideas?
use regular expression:
do_x if file_ext =~ /\a(doc|xls|ppt)\z/
or, if have large enough list of things writing regex feels impractical, like
file_extensions = %w(xls csv doc txt odf jpg png blah blah blah blah blah) do_x if file_extensions.include?(file_ext)
of course there option of testing each value individually:
do_x if file_ext == "doc" || file_ext == "xls" || ... || file_ext == "zzz"
Comments
Post a Comment