A
A
AlexILichev2021-11-24 12:22:56
ruby
AlexILichev, 2021-11-24 12:22:56

How to iterate over a nested hash?

There is a hash:

data = {
  soccer_ball: { name: 'Футбольный мяч', weight: 410, qty: 5 },
  tennis_ball: { name: 'Мяч для тенниса', weight: 58, qty: 10 },
  golf_ball: { name: 'Мяч для гольфа', weight: 45, qty: 15 }
}

I can't walk through it so that the output is like this

футбольный мяч вес: 410 грамм, количество: 5 шт

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-11-24
@AlexILichev

data.each_value{|n|
  puts("#{n[:name]}: вес #{n[:weight]} г., количество #{n[:qty]} шт.")
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question