how do i loop over a hash of hashes in ruby

Matt Elhotiby picture Matt Elhotiby · Feb 14, 2012 · Viewed 138.4k times · Source

OK so i have this hash

 h
 => {"67676.mpa"=>{:link=>"pool/sdafdsaff", :size=>4556}} 

>  h.each do |key, value|
>     puts key
>   puts value
>   end
67676.mpa
linkpool/sdafdsaffsize4556

how do i access the separate values in the value hash on the loop

Answer

shingara picture shingara · Feb 14, 2012

Value is a Hash to so you need iterate on it or you can get only values:-

h.each do |key, value|
  puts key
  value.each do |k,v|
    puts k
    puts v
  end
end