In the following two examples, I do the same by creating a String constant and using the concat method to change it. Since it is persistent, I expect a compiler warning, but I only get it in the second example when I use the assignment operator. Why is this?
X = "hello"
X.concat(" world")
puts X
X = "hello"
X = X.concat(" world")
puts X
Since the concat method modifies the string in place, this is usually what I will do, since there is no need to use an assistant operator. So, why does the presence of an assignment operator make the compiler identify these two operations as different?
more or less
source
share