Reputation: 8211
How to determine if string ends with another string regardless of its case?
filename.end_with?(*%w(.ext1 .e2 .extension))
This example only matches if the case matches too. How to match regardless of the case?
Upvotes: 6
Views: 2746
Reputation: 369094
Change filename to lowercase and compare with lowercase extensions.
filename.downcase.end_with?(*%w(.ext1 .e2 .extension))
'MAIN.RB'.downcase.end_with?(*%w(.ruby .rb)) # => true
Upvotes: 9