Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Symbol#to_s

() -> ::String
to_s → string

Returns a frozen string representation of self (not including the leading colon):

Example
:foo.to_s # => "foo"
:foo.name.frozen? # => true

Related: Symbol#inspect

Ruby version changes

  1. 4.1
  2. 3.4
    • The string returned by Symbol#to_s now emits a deprecation warning when mutated, and will be frozen in a future version of Ruby. These warnings can be enabled with -W:deprecated or by setting Warning[:deprecated] = true. [Feature #20350]

See also #to_proc #to_sym #swapcase #upcase also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0