6 ms·
They are... s = "hello" s << " world" s # hello world
by reflectiv 13y ago
They 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"