嗨,我剛開始學習Ruby,我通過一個數組我創建看起來像這樣試圖循環:我如何在Ruby中循環數組?
server[0] = ['hostname' => 'unknown01', 'ip' => '192.168.0.2', 'port' => '22']
server[1] = ['hostname' => 'unknown02', 'ip' => '192.168.0.3', 'port' => '23']
server[2] = ['hostname' => 'unknown03', 'ip' => '192.168.0.4', 'port' => '24']
我嘗試使用此代碼:
i=0
server[i].each do |x|
print x['hostname']
print x['ip']
i+=1
end
,但它只能通過服務器循環[0]我怎麼可以通過服務器循環[0-3]