Project

General

Profile

Actions

Feature #22137

open

Change `Symbol#to_s` to return frozen strings

Feature #22137: Change `Symbol#to_s` to return frozen strings
1

Added by byroot (Jean Boussier) 6 days ago. Updated 6 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:125891]

Description

Since Ruby 3.4 ([Feature #20350]) Symbol#to_s returns a chilled string, meaning mutating it emits a deprecation warning.

I believe it's now time to act on this deprecation, I'd like to request that on Ruby 4.1, Symbol#to_s always return a frozen string.

Several very large codebases include Shopify and GitHub have been running with Symbol.alias_method(:to_s, :name) without any compatibility issues whatsoever.

Making this change would allow to progressively get rid of an annoying pattern in performance sensitive code:

arg.is_a?(Symbol) ? arg.name : arg.to_s

Related issues 1 (0 open1 closed)

Related to Ruby - Feature #20350: Return chilled string from Symbol#to_sClosedActions
Actions

Also available in: PDF Atom