Advanced Ruby • Exercise 3/5

Deep Dig

00:00
0
15 points

Instructions

Create a function get_city that extracts the city from a nested
user hash structure. Return nil if any key is missing.

Use dig for safe nested access:
ruby
hash = { user: { address: { city: "NYC" } } }
hash.dig(:user, :address, :city) # => "NYC"
hash.dig(:user, :phone, :number) # => nil (no error!)

Expected structure:
ruby
{ user: { address: { city: "..." } } }

Your Code

Results

Click "Run Tests" to see results