I get confused why .method! gives you an error whenever it gets nothing to do in the code unlike .method.
Here is an example where I got stuck:
print "Input something that containts 's'."
user_input = gets.chomp.downcase!
if user_input.include? "s"
puts "We got your 's'!"
s = 'ABC' s.downcase s # 'ABC'
As you can see
s is still
downcase return the string downcased, not modify my object
s.downcase! s # 'abc'
permits me to modify my
s and I can avoid to do
s = s.downcase
issue is the
downcase! method returns
nil if no changes are made so your
nil and that's a problem in the next line when you call
include? on it.
Anyway, you are calling downcase on a temporary object, not on your own object, so you can easily use
downcase in this case
user_input = gets.chomp.downcase