End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Symbol#name
sym.name → string
string.c
View on GitHub ↗
VALUE
rb_sym2str(VALUE sym)
{
}
Returns the name or string corresponding to sym. Unlike to_s, the returned string is frozen.
Example
:fred.name #=> "fred" :fred.name.frozen? #=> true :fred.to_s #=> "fred" :fred.to_s.frozen? #=> false
Ruby version changes
-
3.0
-
Symbol#namehas been added, which returns the name of the symbol if it is named. The returned string is frozen. [Feature #16150]
-