Edit: Having an exclamation point (aka "bang") at the end of a method name in ruby means "handle with care". From Matz himself:
The bang (!) does not mean "destructive" nor lack of it mean non
destructive either. The bang sign means "the bang version is more
dangerous than its non bang counterpart; handle with care". Since
Ruby has a lot of "destructive" methods, if bang signs follow your
opinion, every Ruby program would be full of bangs, thus ugly.
(For the full thread, see @sawa's link in the comments.)
For the method in question, downcase
is making a copy of the given string, modifying that, and returning that copy as a result. Whereas downcase!
modifies the string itself.
In the first case, you're modifying the variable stored in gets.chomp
, in the second you're modifying user_input
.
Note that if you call user_input.downcase
on the last line (instead of user_input.downcase!
) it won't actually change user_input
, it just returns a copy of the string and makes the copy lowercase.