Recall & Review
beginner
What is a Symbol in Ruby?
A Symbol is a lightweight, immutable identifier used mainly as names or keys. It is unique and stored only once in memory.
Click to reveal answer
beginner
Why are Symbols considered immutable in Ruby?
Symbols cannot be changed after creation. This immutability means their value and identity stay constant throughout the program.
Click to reveal answer
intermediate
How do Symbols differ from Strings in Ruby?
Symbols are immutable and stored once, making them memory-efficient for repeated use. Strings are mutable and can have many copies in memory.
Click to reveal answer
intermediate
What happens if you create the same Symbol multiple times?
Ruby reuses the same Symbol object for identical names, so all references point to the same memory location.
Click to reveal answer
beginner
Give an example of creating a Symbol in Ruby.
You create a Symbol by prefixing a name with a colon, like :example. This creates a Symbol named 'example'.
Click to reveal answer
Which of the following is a Symbol in Ruby?
✗ Incorrect
Symbols start with a colon, like :my_symbol.
What is true about Symbols in Ruby?
✗ Incorrect
Symbols are immutable and unique identifiers.
If you create :apple twice in Ruby, what happens?
✗ Incorrect
Ruby reuses the same Symbol object for identical names.
Which is a benefit of using Symbols over Strings as keys in hashes?
✗ Incorrect
Symbols are immutable and stored once, making them memory-efficient and faster for lookups.
How do you create a Symbol named 'status' in Ruby?
✗ Incorrect
A Symbol is created by prefixing the name with a colon, like :status.
Explain what a Symbol is in Ruby and why it is immutable.
Think about how Symbols are used as names or keys.
You got /3 concepts.
Describe the difference between Symbols and Strings in Ruby.
Consider memory use and mutability.
You got /4 concepts.