Reputation: 6346
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"
Upvotes: 2
Views: 425
Reputation: 14943
ext =~ /(.xlsx$)|(.xls$)|(.ods$)/
irb(main):009:0> '.xlsx' =~ /(.xlsx$)|(.xls$)|(.ods$)/
=> 0
irb(main):010:0> '.xlsa' =~ /(.xlsx$)|(.xls$)|(.ods$)/
=> nil
Upvotes: 1