Gsub - variables that are equal are changed


#1

I wanted to keep the original text entry so that I could use it later in the program.
Here is my code.

print "Write your name:"
name1 = gets.chomp
name1.downcase!
if name1.include? "s"
    name2 = name1
    puts"#{name1} "
    name2.gsub!(/s/,"th")
    puts "#{name1}, Daffy says your name is #{name2}"
else
    print name1
end

Why do "name1 and "name2 get changed using gsub?


#2

@rheadon,
Maybe if you read the article
http://stackoverflow.com/questions/612189/why-are-exclamation-marks-used-in-ruby-methods
you will understand the consequence of using the exclamation-mark-! operator.


#3

I apologize. Too clarify here is the output that I get.

Write your name: sam
sam
tham, Daffy says your name is tham
nil

I am not using gsub on name1 but in the puts statement name1 has substituted "s" with "th".
I understand that name2 should be modified but why name1?