Bird
0
0

Why are Ruby symbols considered more memory efficient than strings when used repeatedly?

hard📝 Conceptual Q10 of 15
Ruby - Variables and Data Types

Why are Ruby symbols considered more memory efficient than strings when used repeatedly?

ABecause each symbol is stored only once in memory.
BBecause symbols are mutable and can be changed.
CBecause symbols are converted to integers internally.
DBecause symbols are garbage collected more often.
Step-by-Step Solution
Solution:
  1. Step 1: Understand symbol storage

    Each symbol is stored once in memory and reused, unlike strings which create new objects.
  2. Step 2: Compare with strings

    Strings create new objects each time, consuming more memory; symbols save memory by reusing one object.
  3. Final Answer:

    Because each symbol is stored only once in memory. -> Option A
  4. Quick Check:

    Symbol memory efficiency = C [OK]
Quick Trick: Symbols are stored once and reused, saving memory [OK]
Common Mistakes:
  • Thinking symbols are mutable
  • Believing symbols convert to integers
  • Assuming symbols are garbage collected frequently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes