Bird
0
0

Which of the following is the correct syntax to get all keys from a hash named h?

easy📝 Syntax Q3 of 15
Ruby - Hashes
Which of the following is the correct syntax to get all keys from a hash named h?
Ah.get_keys()
Bh.keys()
Ch.key()
Dh.all_keys
Step-by-Step Solution
Solution:
  1. Step 1: Recall the method name for keys

    The correct method to get all keys is keys, called with parentheses optionally.
  2. Step 2: Check syntax correctness

    h.keys() is valid Ruby syntax and returns an array of keys.
  3. Final Answer:

    h.keys() -> Option B
  4. Quick Check:

    Method to get keys = keys() [OK]
Quick Trick: Use keys() to get all keys from a hash [OK]
Common Mistakes:
MISTAKES
  • Using key() instead of keys()
  • Using non-existent methods like get_keys
  • Trying to access keys as properties

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes