I am new to ruby, I am trying to write a method that checks if the word includes "hello" case insensitive e.g "HelLO" would still be true.
CodePudding user response:
I think the easiest approach is to downcase both string and do the comparing. Like this:
'HellO'.downcase.include?('hello')
# true
CodePudding user response:
I can think of two approaches:
downcase
before comparingstr = "HelLO" str.downcase.include?('hello') #=> true
use case-insensitive regular rexpression
str = "HelLO" str.match?(/hello/i) #=> true