Ruby - Thirth Meanth War, If Branch Part 1



Hey there. Repeated error on this lesson, syntax is correct, should be getting no error:

undefined method ='include?' for nil:NilClass

print "Enter a string: "
user_input = gets.chomp.downcase!

if user_input.include? "s"
    print "hi"

Anyone want to take a stab at this?


Try it without the exclamation mark.


Would help if you explained why?

The downcase! method returns nil when gets.chomp is all lowercase, already. Be sure to include at least one capital letter in the input.

The method is an 'in-place' operation. To have it return a valid string when no uppercase letters have been entered, use the assignment method (without the ! modifier).

user_input = gets.chomp.downcase


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.