FAQ: Putting the Form in Formatter - Formatting with String Methods

Actually this seems to happen only if you apply the bang during the gets, but doesn’t happen (i.e. it will not print blanks) if apply ! at the output (print or puts).

So ’ gets.chomp.capitalize! ’ will print blanks for correctly formatted inputs but ’ puts “Your name is: #{first_name}!” ’ will handle correctly formatted input.

@laconicsky So just to reiterate the gist of your explanation (which totally makes sense btw), “.capitalize” is a string method that capitalizes the first letter of a string. But when you try to apply this string method to a variable with an assigned string value, it won’t modify it. You would need a “.capitalize!” method in order to modify the variable that already contains an assigned string value correct?

:+1: correct. Hope that’s all good for you now.

1 Like