Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Multiple OR Evaluations For String Value

I was wondering if there was a dry way of writing the following in Ruby:

ext == ".xlsx" || ext == ".xls" || ext == ".ods"   

My initial thought was the following which doesn't seem to work as expected:

ext == ".xlsx" || ".xls" || ".ods"   
like image 658
Noz Avatar asked Aug 09 '26 16:08

Noz


2 Answers

Yes, there is...

['.xlsx','.xls','.ods'].include? ext
like image 148
Alcides Queiroz Avatar answered Aug 12 '26 06:08

Alcides Queiroz


%w(.xlsx .xls .ods).include? ext
like image 22
OscarRyz Avatar answered Aug 12 '26 08:08

OscarRyz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!