I don't understand your code particularly, but you may be having a common beginner's mistake to use destructive methods when you shouldn't. upcase!
will return nil
when no upcase takes place, and that may be causing your problem. Especially, you are doing upcase!
on a string $main
, and then doing upcase!
on it again. If there were no upcasing in the first upcase!
, then you would be calling the second upcase!
on nil
, which will raise an error. Even if there were upcasing in the first upcase!
, the second upcasing will surely not take place, and you will get nil
even in that case. It does not makes sense at all. Change upcase!
to upcase
.
By the way, I don't understand why you are using chomp
correctly (instead of chomp!
), but are using upcase!
(instead of upcase
). And I also don't understand why you are using the former chained after gets
(which is okay) but are doing the latter within each condition in if
elsif
end
block (which is not only redundant, but problematic).
Furthermore, it looks like you should be using case
end
instead.