3 ms·
e.g. 1000.times { "hello" } creates strings 1000 times but: 1000.times { "hello".freeze } only one time. The thing about frozen strings is they can't be change
by dorianm 10y ago
e.g. 1000.times { "hello" } creates strings 1000 times but: 1000.times { "hello".freeze } only one time.
The thing about frozen strings is they can't be changed "inline":
e.g. : "Hello".freeze << " world" doesn't work but "Hello".freeze + " world" does because it creates a new string.
(It's funny because << is often recommended as an optimization)