Bird
0
0

Identify the error in this Ruby hash creation:

medium📝 Debug Q6 of 15
Ruby - Hashes
Identify the error in this Ruby hash creation:
h = { :name => "John", age: 25, "city" => "NY" }
AMixing symbol and string keys is not allowed
BMissing comma between pairs
CNo error, this is valid syntax
DKeys must all be strings
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax validity

    Ruby allows mixing symbol keys and string keys in the same hash.
  2. Step 2: Verify commas and key-value pairs

    All pairs are separated by commas and keys are valid.
  3. Final Answer:

    No error, this is valid syntax -> Option C
  4. Quick Check:

    Mixed keys allowed in hashes [OK]
Quick Trick: Ruby hashes can mix symbol and string keys [OK]
Common Mistakes:
  • Thinking mixed keys cause errors
  • Forgetting commas between pairs
  • Assuming keys must be uniform type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes