Capitalize! in Ruby?

Hi

Am completing the Ruby intro but am confused by “Formatting with String Methods” https://www.codecademy.com/courses/learn-ruby/lessons/putting-the-form-in-formatter/exercises/formatting-with-string-methods?action=resume_content_item

I’m a little confused I wrote it as follows (see below) and it works? I cant understand why then you need to write

This is how the instructions are saying to write it
print “What’s your first name?”
firstname = gets.chomp
firstname =firstname.capitalize
firstname1 =firstname.capitalize!

But isnt this the same as below which BTW works?
print “What’s your first name?”
firstname = gets.chomp
firstname =firstname.capitalize!

well, capitalize and capitalize! work different, that is what the example is there to show.

Here is another example to help clarify things:

test = "abc"
test.capitalize
puts test
test.capitalize!
puts test

capitalize returns a new string, leaving the original string as it is, while capitalize! modifies the original string.