Bird
0
0

Which of the following is the correct syntax to use dig on a hash h = {x: {y: 10}} to access the value 10?

easy📝 Syntax Q3 of 15
Ruby - Hashes
Which of the following is the correct syntax to use dig on a hash h = {x: {y: 10}} to access the value 10?
Ah.dig[:x, :y]
Bh.dig(:x, y)
Ch.dig(:x)[y]
Dh.dig(:x, :y)
Step-by-Step Solution
Solution:
  1. Step 1: Recall dig method call syntax

    dig is called with parentheses and keys as arguments, like dig(:x, :y).
  2. Step 2: Identify correct syntax among options

    Only h.dig(:x, :y) uses correct method call syntax with symbols as keys.
  3. Final Answer:

    h.dig(:x, :y) -> Option D
  4. Quick Check:

    Use parentheses and symbols in dig call [OK]
Quick Trick: Call dig with parentheses and keys as symbols [OK]
Common Mistakes:
  • Using square brackets with dig
  • Passing keys without symbols
  • Missing parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes