Symbols vs Strings
When to use symbols.
What Is a Symbol?
A Symbol is a lightweight, immutable name written with a leading colon, like :name. Symbols are often used as identifiers and hash keys.
status = :active
puts status
puts status.classSymbols Are Immutable
Unlike strings, symbols cannot be changed. Once :hello exists, it stays the same forever.
puts :hello.frozen?
puts "hello".frozen?All lessons in this course
- Symbols vs Strings
- Creating and Reading Hashes
- Hash Iteration
- Default Values and Merging