Include doesn't work


#1

undefined method `include?' for nil:NilClass

print "What's your input?"
user_input = gets.chomp
user_input = user_input.downcase!
if user_input.include? "s"
    print "found s"
end

#2

If there are no uppercase letters in user_input, the expression on the right becomes nil, which is assigned to user_input.

nil does not have an attribute, `include`.

puts "Test"
user_input = gets.chomp
user_input = user_input.downcase!
puts user_input

# Test
# all lower case
# nil

Trying to call on the include method results in,

undefined method include? for nil:NilClass

#3

thanks this helped me a lot


#4

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