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"
就在这里...
['.xlsx','.xls','.ods'].include? ext
%w(.xlsx .xls .ods).include? ext
ext =~ /(.xlsx$)|(.xls$)|(.ods$)/
irb(main):009:0> '.xlsx' =~ /(.xlsx$)|(.xls$)|(.ods$)/
=> 0
irb(main):010:0> '.xlsa' =~ /(.xlsx$)|(.xls$)|(.ods$)/
=> nil
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.