Skip to content

Symbol

class Amethyst::Runtime::Symbol

A lightweight, interned identifier. Every symbol literal such as :name compiles to a Symbol, and symbols with the same name are always the same instance, so comparing them is a reference check.

role = :admin
puts role # :admin
puts role.name # admin
puts role == :admin
getter name: String

The symbol’s name, without the leading :.

==

def ==(other: Symbol?): Bool

true when both sides are the same symbol. Because symbols are interned, this never compares strings.

def to_s: String

The symbol as written in source, e.g. ":admin".

C# code creates symbols with the static Symbol.For method, which returns the canonical instance for a name:

var admin = Amethyst.Runtime.Symbol.For("admin");

Two null-tolerant helpers convert between symbols and names. The compiler uses them where a symbol is stored as a string, such as the members of an attribute class:

Method Returns
Symbol.FromName(string? name) The symbol for name, or null for null.
Symbol.NameOf(Symbol? symbol) The symbol’s name, or null for null.