Skip to content

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

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

  1. 3.0
    • Symbol#name has been added, which returns the name of the symbol if it is named. The returned string is frozen. [Feature #16150]

See also #match? #next #match #size also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1