[ruby-core:117526] [Ruby master Feature#20350] Return chilled string from Symbol#to_s
From:
"byroot (Jean Boussier) via ruby-core" <ruby-core@...>
Date:
2024-04-16 06:41:14 UTC
List:
ruby-core #117526
Issue #20350 has been updated by byroot (Jean Boussier). > `Symbol#name` returns frozen string. It is not enough? It doesn't work well with duck typing. It's common to have a method that call `to_s` on the argument, and the argument can be a Symbol or another type: ```ruby def some_method(arg) arg = arg.to_s # do things end ``` We can debate the merits of such design of course, but from my experience it's extremely common. Years after `Symbol#name` introduction, `Symbol#to_s` remains visible on production profiles, and running https://github.com/Shopify/symbol-fstring/ still provide a small, but noticeable improvement. ---------------------------------------- Feature #20350: Return chilled string from Symbol#to_s https://bugs.ruby-lang.org/issues/20350#change-107915 * Author: Dan0042 (Daniel DeLorme) * Status: Open ---------------------------------------- During Ruby 2.7 development there was an attempt to return a frozen string from Symbol#to_s (#16150#note-22) This had to be rolled back due to incompatibility, but now we have chilled strings (#20205) Symbol#to_s can safely return a chilled string, giving developers time to fix warnings before switching to a frozen string. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- [email protected] To unsubscribe send an email to [email protected] ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/