Purpose of the answer2 = answer.capitalize line


#1




Question... what is the purpose of the "first_name2 = first_name.capitalize" line (and same for the corresponding last_name2, city2, and state2 lines)?? I am unsure of what it is doing, if it is the first_name.capitalize! underneath it that is actually doing the capitalization.

Thanks!


print "What's your first name?"
first_name = gets.chomp
first_name2 = first_name.capitalize
first_name.capitalize!
print "What's your last name?"
last_name = gets.chomp
last_name2 = last_name.capitalize
last_name.capitalize!
print "Which city are you from?"
city = gets.chomp
city2 = city.capitalize
city.capitalize!
print "Which state?"
state = gets.chomp
state.upcase!
state2 = state.upcase
puts "Your name is #{first_name} #{last_name}, and you are from #{city}, #{state}"


#2

surNom = lastName.capitalize

This assigns the new state to the variable, without changing the actual state of lastName.

lastName.capitalize!

This changes the state of lastName in place.


#3

Oooh ok, got it. Thanks for your help


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.