ruby - How to do if X is equal to either one of these values (xxx,eeee,yyyy,dadadad) -


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

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -