I asked this question not to long ago - "Does 'upcase!' not mutate a variable in Ruby?
". As a follow up, I changed the code a bit and I'm still not sure what's going on. Why doesn't +
modify the object that str
is pointing to? I'm not re-assigning str
again right?
def change_string(str)
str + "?"
str.upcase!
end
phrase = "what time is it"
change_string(phrase)
puts phrase
The phrase is upcased but the question mark is not added. If I remove the last line that upcases the object then the "?" is appended. Why is this? Is it because +
is non destructive and upcase!
is? Or is there something else happening here that I'm missing.