Why can't i use the ".include?"


#1

This is my code

print "input"
user_input = gets.chomp.downcase!

if user_input.include? "s"
print "input includes ´s´ =D "
end
================================================

and it produces this output:

input sa
undefined method `include?' for nil:NilClass
================================================

Why dosen't it work properly?


#3

This will happen when the input contains no upper case letters. If you wish to be able to enter only lower case, then change .downcase! to .downcase when assigning, otherwise, be sure that the input contains at least one upper case letter.


#4

aah, i see thanks a lot :smiley:


#5

i have got same error but once i typed uppercase input for user it worked.
Thanks for the tip.