Two ways to write "the same word"
Two values, same letters, different objects
"name"
:name
Both hold the letters n-a-m-e and sound the same read aloud. They're different kinds of object, though: a String and a Symbol, each with its own rules. This course covers what separates them and when to use each.
Symbol syntax: a colon in front
A symbol literal is a colon followed by a name, with no quotes.
:name
:active
:admin
That's all the syntax: a colon right before a valid identifier. There are no quotes because a symbol isn't text the way a string is. The rest of the course explains the difference.
Confirming two different classes
The Ruby: programmer happiness course showed that everything is an object and every object has a class. "name" and :name have different classes.
"name".class # => String
:name.class # => Symbol
String covers ordinary text, which a later course covers fully. Symbol is a separate class, and the remaining six lessons cover the practical differences that creates.
What they have in common
First, what they share. Both hold a sequence of characters, both can be compared, and each converts to the other. :name == :name and "name" == "name" are both true. Neither is the wrong choice in general. They're tools for different jobs, the contextual choice Ruby: programmer happiness described in its lesson 4.
What this course covers
- Lesson 1, Two ways to write "the same word": String and Symbol, two different classes for what sounds like the same value (you are here)
- Lesson 2, Mutable strings, immutable symbols: one of them can change in place, the other never can
- Lesson 3, Object identity: why every
:namein a program is the same object - Lesson 4, Memory efficiency and comparison speed: why that identity matters at real scale
- Lesson 5, When to use symbols: hash keys, fixed identifiers, and where strings still win
- Lesson 6, Converting between them:
to_symandto_s - Lesson 7, Putting it together: a small challenge choosing the right one deliberately
By the end, you'll know why real code uses "status" in one place and :status in another.
Keep going with lesson 2
Mutable strings, immutable symbols
Shows how strings change in place, how mutation differs from reassignment, and why symbols reject mutation.
A free account also gives you the quizzes, your progress and notes, and the discussion.