h = {
users: {
u_548912: {
name: "John",
age: 30
},
u_598715: {
name: "Doe",
age: 30
}
}
}
Given a hash like above, say I want to get user John, I can do
h[:users].values.first[:name] # => "John"
In Ruby 2.3 use Hash#dig
can do the same thing:
h.dig(:users, :u_548912, :name) # => "John"
But given that the u_548912
is just a random number(no way to know it before hand), is there a way to get the information still using Hash#dig
?