3 ms·
I believe strings are mutable in Ruby.
by meepmorp 13y ago
I believe strings are mutable in Ruby.
- reflectiv 13y agoThey are... s = "hello" s << " world" s # hello world
- dbaupp 13y agoIs that allocating a new buffer, leaving the "hello" string to be collected by the GC?
- tedunangst 13y agoNo, it expands the existing buffer. (leaving " world" to be collected). Note that the following is different and more like what you're thinking. a = a + " world"
- jeorgun 13y agoNo, it's operating in place: def append_world(str) str << " world" end a = "hello" append_world(a) a #=> "hello world"