-2

I have the following hash :

{
  "2017-01-01" => {
    "2"=> [
      {:a=>"2017-01-01", :b=>"2", :c=>"1"},
      {:a=>"2017-01-01", :b=>"2", :c=>"2"}
    ]
  },
  "2017-01-02" => {
    "5"=> [
      {:a=>"2017-01-02", :b=>"5", :c=>"1"}
    ]
  }
}

I would iterate separately

1)first iteration

{
 {:a=>"2017-01-01", :b=>"2", :c=>"1"},
 {:a=>"2017-01-01", :b=>"2", :c=>"2"}
}

2) second iteration

{
 {:a=>"2017-01-02", :b=>"5", :c=>"1"}
}

How can I do? Thanks in advance.

sirion1987
  • 111
  • 4
  • 13

1 Answers1

1

answer for your question is in How to iterate over a hash in Ruby? check it.

hash.each do |key, array|
  puts array
end

if 'array' again is a hash, then you need to loop it as follows

hash.each do |key, hash2|
  hash2.each do |key2,array|
    puts array
  end 
end
Community
  • 1
  • 1
jithya
  • 428
  • 4
  • 13