0Pricing
Ruby Academy · Lesson

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.class

Symbols 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

  1. Symbols vs Strings
  2. Creating and Reading Hashes
  3. Hash Iteration
  4. Default Values and Merging
← Back to Ruby Academy