From: brabuhr@... Date: 2009-11-29T01:21:55+09:00 Subject: Re: iterate over a hash with values containing a array of hashes On Sat, Nov 28, 2009 at 10:15 AM, Bruno Moura wrote: > I need iterate over a hash with values containing a array of hashes for > build a string with comma values > > I tried tranform this ... > into a string like this: ... > I believe that this task isn't complex, but for me is difficult to do > now How far were you able to get before getting stuck? The basic way to iterate over a Hash is each: irb(main):001:0> hash = {"A" => 1, "B" => 2} => {"A"=>1, "B"=>2} irb(main):002:0> hash.each{|key, value| irb(main):003:1* p value irb(main):004:1> } 1 2 => {"A"=>1, "B"=>2} When the values stored in the Hash are Arrays, you can use each within each: irb(main):005:0> hash = {"A" => [1,2,3], "B" =>[4,5,6]} => {"A"=>[1, 2, 3], "B"=>[4, 5, 6]} irb(main):006:0> hash.each{|key, array| irb(main):007:1* p key irb(main):008:1> array.each{|element| irb(main):009:2* p element irb(main):010:2> } irb(main):011:1> } "A" 1 2 3 "B" 4 5 6 => {"A"=>[1, 2, 3], "B"=>[4, 5, 6]} Does that help get you moving in the right direction?