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.
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.
I can think of two approaches:
downcase before comparing
str = "HelLO"
str.downcase.include?('hello')
#=> true
use case-insensitive regular rexpression
str = "HelLO"
str.match?(/hello/i)
#=> true
I think the easiest approach is to downcase both string and do the comparing. Like this:
'HellO'.downcase.include?('hello')
# true