Why that (!) need finished the capitalize!.. when ı remember it,that is wrong


#1


#2

When you use the !, your variable is changed.

To see the difference between using and not using !, try this code:

# get some info from the user
print "What's your first name?"
first_name = gets.chomp

# print the info with no !
first_name.capitalize
puts "Your name is #{first_name}"

# print the info with a !
first_name.capitalize!
puts "Your name is #{first_name}"

Capitalizing/ formatting with string methods( capitalize!)
#3

ı learn that. thank you =)


#4

OK so when you want to capitalize the string (words/phrases) then you don't need ( ! ).
For example:
Print "This is my string".capitalize

On the other hand, if you are printing a variable, you need ( ! ) for the content to be capitalized.
For example:
my_variable.capitalize!

Correct me if i am wrong:) but i think this is how it works


#5

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