Yes, strings in Ruby, unlike in Python, are mutable.
s += "hello" is not appending "hello" to s – an entirely new string object gets created. To append to a string ‘in place’, use <<, like in:
s = "hello"
s << " world"
s # hello world
Yes, strings in Ruby, unlike in Python, are mutable.
s += "hello" is not appending "hello" to s – an entirely new string object gets created. To append to a string ‘in place’, use <<, like in:
s = "hello"
s << " world"
s # hello world