Symbol
class Amethyst::Runtime::SymbolA 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 = :adminputs role # :adminputs role.name # adminputs role == :adminMembers
Section titled “Members”getter name: StringThe symbol’s name, without the leading :.
==
def ==(other: Symbol?): Booltrue when both sides are the same symbol. Because symbols are interned, this never
compares strings.
def to_s: StringThe symbol as written in source, e.g. ":admin".
From C#
Section titled “From C#”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. |