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


This is my code

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

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

and it produces this output:

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

Why dosen't it work properly?


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.


aah, i see thanks a lot :smiley:


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