Iterating an array with a hash

sorry if this duplicates but I sent it about 5 hours ago and it hasn’t
shown up yet…

trying to do this in irb/console…

@sect = Array.new
info = { “outsection” => “I/A”, “outtitle” => “I” }
@sect << info
info = { “outsection” => “I/B”, “outtitle” => “B” }
@sect << info

for sect in @sect
puts sect.outsection
end

NoMethodError: undefined method outsection' for {"outtitle"=>"I", "outsection"=>"I/A"}:Hash from (irb):127 from (irb):126:ineach’
from (irb):126

how do I iterate over the array to get the individual hash elements?

Craig

Craig W. wrote:

puts sect.outsection

sect here is a hash, so you need to use Hash methods to access the
parts:

puts sect[‘outsection’]

On Fri, 2008-03-14 at 07:53 +0100, Mark B. wrote:

Craig W. wrote:

puts sect.outsection

sect here is a hash, so you need to use Hash methods to access the
parts:

puts sect[‘outsection’]


duh…sometimes where you’re in the forest, all you see is trees.

of course

Thanks

Craig