Leshy
Leshy

Reputation: 97

Ruby .include? method is not accepted as a valid method

I have this Ruby code in a script:

$dev_input=gets.chomp.downcase!
    if $dev_input.include? "/"
        check_developer_commands()
    else
        puts ">>Invalid Command<<"
        continuing_dev_mode()
    end

The problem is, whenever I try and run the script containing this, I get an error spat back at me that says :

dev_continue_main.rb:3:in 'continuing_dev_mode': undefined method 'include?' for nil:NilClass (NoMethodError)

Any idea what this error might be? I'm pretty sure that this is the proper way to use the .include? method. I've done some research, looked at tutorialspoint.com and some other sites, but they agree that this is the proper way to use this method.

I checked the error message and it confirmed that the third line in this script/my example is the source of the problem, so it's not some other instance of this method throwing an error.

Any thoughts? Please Help!

Upvotes: 0

Views: 65

Answers (1)

sawa
sawa

Reputation: 168101

The problem is that $dev_input is nil. That stems from applying downcase! in defining $dev_input. I don't know why you want to possibly assign nil to $dev_input, and at the same time claim that calling include? on it is the right way. I don't get your intention for doing that, but if you instead had $dev_input = gets.chomp.downcase, then it wouldn't cause such error.

Upvotes: 3

Related Questions