.include? undefined method


Here are my instructions:


We want to check user_input for the substring "s".
01. Write an if statement in the editor. It should check to see if user_input includes "s".
02. For now, print a string of your choice to the console if it finds "s".

Here is my code:

Anybody know what is going on?


This is a really annoying bug I spent 3 days on this part.

Here is what worked:


The "=" operator is already modifying "user_input", so using "!" is redundant and doesn't work.

You either use

user_input = gets.chomp.downcase


user_input = gets.chomp

As for why you can't modify directly the content behind the gets method, my guess is that it's not an object that is reachable by "!". Someone with more knowledge on Ruby might know exactly the reason.


Your theories make sense . The error does not. If the modification cannot be reached or just not occur why does it tell me .include? is not a method.


It doesn't say include? is not a method, it says include? is not a method for nil.NilClass, which means that user_input is not an object registered as a string at that line of code, which means that the assignation of value combining "!" and "=" failed and as a consequence Ruby decided to register user_input as a nil object.

At least that's my understanding of it, I'm sure true Rubyists will provide more informations if they come across this thread.


That's interesting. Thank you for your wisdom