TheHat
TheHat

Reputation: 70

include downcase in if statement for ruby

I want to compare if one path is included in the other and I don't care about case sensitivity, is this a right thinking:

if row[0].to_s.downcase != "" && File.read(commit_file).include?(row[0].downcase)
        .
        .
        .       
end

thnx!!!

Upvotes: 1

Views: 422

Answers (2)

Md. Farhan Memon
Md. Farhan Memon

Reputation: 6121

You can use casecmp, it does exactly what you need..one check will do the trick..

if File.read(commit_file).casecmp(row[0].to_s).zero?

Upvotes: 1

AlexW
AlexW

Reputation: 3399

File.read returns the content of the file as a String. So, to achieve what you want, you would need to convert both Strings you're working with to lowercase. You can achieve it by:

if row[0].to_s != "" && File.read(commit_file).downcase.include?(row[0].to_s.downcase)

Upvotes: 2

Related Questions