Bird
0
0

In Ruby, how do you access the value associated with the key :age in a hash named person?

easy📝 Conceptual Q1 of 15
Ruby - Hashes
In Ruby, how do you access the value associated with the key :age in a hash named person?
Aperson->age
Bperson.age
Cperson[:age]
Dperson['age']
Step-by-Step Solution
Solution:
  1. Step 1: Understand hash key access in Ruby

    Ruby hashes use square brackets with the key symbol or string to access values.
  2. Step 2: Apply correct syntax for symbol keys

    Since the key is a symbol :age, use person[:age] to access its value.
  3. Final Answer:

    person[:age] -> Option C
  4. Quick Check:

    Hash key access = person[:age] [OK]
Quick Trick: Use square brackets with symbol keys to access hash values [OK]
Common Mistakes:
  • Using dot notation for hash keys
  • Using string keys when symbol keys are defined
  • Using arrow operator which is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes