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
symbol.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/symbol.rb, line 11
def to_s
Primitive.attr! :leaf
Primitive.cexpr! 'rb_sym2str(self)'
end
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
-
4.1
-
Symbol#to_snow returns a frozen string. [Feature #22137]
-
-
3.4
-
The string returned by
Symbol#to_snow emits a deprecation warning when mutated, and will be frozen in a future version of Ruby. These warnings can be enabled with-W:deprecatedor by settingWarning[:deprecated] = true. [Feature #20350]
-