Issue #9278 has been updated by headius (Charles Nutter).


Adding .freeze to the frequently-used strings has the same result for me, and it doesn't also gather up other strings that may not need/want to be immutable.

https://gist.github.com/ColinDKelley/8156708

I have the same objections to this magic comment that I did when it was proposed before:

* A magic comment should not completely change the semantics of a literal type. Encoding magic comments do not suffer from the same issue since they only change how the bytes of the strings are interpreted by the encoding subsystem...they do not change semantics.

* A magic comment is far removed from the actual literal strings, meaning that every developer that enters a file will have to keep in mind whether the strings have been forced to be immutable before doing any work with literal strings.

* Although this eliminates or reduces calls to .freeze, it causes the opposite effect to get a mutable string in the same file...specifically, you have to call .dup.

I think it would be better to consider adding the String#f method proposed during the rework of .freeze optimizations. Adding a .f to a literal string is not very much to ask, and in your particular script, it would actually add *fewer* characters to the code than the magic comment.
----------------------------------------
Feature #9278: Magic comment "immutable: string" makes "literal".freeze the default for that file
https://bugs.ruby-lang.org/issues/9278#change-43937

Author: colindkelley (Colin Kelley)
Status: Open
Priority: Normal
Assignee: 
Category: core
Target version: 2.1.0


Building on https://bugs.ruby-lang.org/issues/9042, this pull request adds the magic comment # -*- immutable: string -*- that implies .freeze on every string literal in the file. To get a mutable string in a file that starts with the magic comment, use String.new or ''.dup.

Here is a corresponding github pull request:

    https://github.com/ruby/ruby/pull/487

For more details, background, and rationale, please see this blog post:

    http://development.invoca.com/magic-comment-immutable-string-makes-ruby-2-1s-literal-freeze-optimization-the-default/


-- 
http://bugs.ruby-lang.org/