3 ms·
It's not sending a message - that would defeat the purpose. It's constructing a frozen string, reusing an existing one when possible. Prior to 2.1: def fo
by bct 13y ago
It's not sending a message - that would defeat the purpose. It's constructing a frozen string, reusing an existing one when possible.
Prior to 2.1:
def foo
"bar".freeze
end
does these things every time `foo` is called:
1. copies the characters 'b', 'a', and 'r' into a mutable string
2. sends the message `freeze` to the new string, which...
3. marks the string as frozen.
In 2.1 `"bar".freeze` is equivalent to `"bar"f`, which will not make a copy every time `foo` is called. See https://bugs.ruby-lang.org/issues/8579 https://bugs.ruby-lang.org/issues/8579 for more discussion.
- jamesbritt 13y agoI see. Thank you.