3 ms·
Now instead of "foo".freeze it's "foo"f, but how frequently will that save you time/trouble? Worse, it seems to break the model of "interact with objects by se
by jamesbritt 13y ago
Now instead of "foo".freeze it's "foo"f, but how frequently will that save you time/trouble?
Worse, it seems to break the model of "interact with objects by sending messages", where you send a message using
<object>.<message>
Is "foo"f _not_ sending a message? If so, then what is it doing? If yes, then why new syntax?
- bct 13y agoIt'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.
- aaronblohowiak 13y agoit is not sending a message any more than 0b100 is sending a message. this is syntax for a type.