.include? undefined method


#1

Here are my instructions:

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?


#2

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

Here is what worked:


#3

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

You either use

user_input = gets.chomp.downcase

or

user_input = gets.chomp
user_input.downcase!

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.


#4

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.


#5

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.


#6

That's interesting. Thank you for your wisdom