考虑下面的代码:
$ irb
> s = "asd"
> s.object_id # prints 2171223360
> s[0] = ?z # s is now "zsd"
> s.object_id # prints 2171223360 (same as before)
> s += "hello" # s is now "zsdhello"
> s.object_id # prints 2171224560 (now it's different)
似乎可以通过创建新字符串来更改单个字符.然而,添加到字符串显然会创建一个新字符串.
Are strings in Ruby mutable?