Bird
0
0

Which of the following is the correct way to write a Ruby symbol?

easy📝 Syntax Q12 of 15
Ruby - Variables and Data Types

Which of the following is the correct way to write a Ruby symbol?

?
A'my_symbol'
B"my_symbol"
Cmy_symbol
D:my_symbol
Step-by-Step Solution
Solution:
  1. Step 1: Identify symbol syntax in Ruby

    Symbols are written with a colon : followed by a name without quotes.
  2. Step 2: Compare options

    Only :my_symbol uses the correct symbol syntax; others are strings or invalid.
  3. Final Answer:

    :my_symbol -> Option D
  4. Quick Check:

    Symbol syntax = colon + name [OK]
Quick Trick: Symbols start with a colon : followed by name [OK]
Common Mistakes:
  • Using quotes around symbols
  • Writing symbols without colon
  • Confusing symbols with strings
  • Using invalid characters in symbol names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes