Overview - Symbol type and immutability
What is it?
In Ruby, a symbol is a special kind of value that represents a name or identifier. Unlike strings, symbols are immutable, meaning once created, they cannot be changed. Symbols are often used as keys in hashes or to represent method names because they are memory-efficient and fast to compare.
Why it matters
Symbols exist to provide a lightweight, unchangeable identifier that saves memory and speeds up comparisons. Without symbols, programs would use strings everywhere, which can waste memory and slow down performance when repeatedly comparing or using the same names. This efficiency is especially important in large applications or frameworks.
Where it fits
Before learning about symbols, you should understand basic Ruby data types like strings and variables. After symbols, you can explore hashes, method names, and metaprogramming where symbols are heavily used.