Ruby - Thirth Meanth War, If Branch Part 1


#1

Lesson

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"
end

Anyone want to take a stab at this?


#2

Try it without the exclamation mark.


#3

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

#4

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