Great! Now we’ve got our output, but as you can see, we haven’t used string methods to properly capitalize everything yet.
print "This is my question?" answer = gets.chomp answer2 = answer.capitalize answer.capitalize!
capitalize, here. It capitalizes the first letter of a string and makes the rest of the letters lower case. We assign the result to
capitalizeto a variable. Instead you might notice the
!at the end of
capitalize. This modifies the value contained within the variable
answeritself. The next time you use the variable
answeryou will get the results of
After each variable assignment:
city add the
state use the