user6127511 user6127511 - 8 months ago 24
Ruby Question

ruby - iterate through a hash containing key/array value pairs, and iterate through each value

I have an hash that looks like this:

"key1": [
"key2": [
"key3": [
"key4": [

How do I iterate through every keyN, while also looping through all the values in that key?

I have an array with all the keys if that helps.



Pretty simple, really:

hash.each do |name, values|
  values.each do |value|
    # ...

You can do whatever you want with name and value at the lowest level.