【发布时间】:2015-01-01 04:38:12
【问题描述】:
我想在单列中打印哈希数组,但我的输出是连续打印
products = {"name":"kumar","results":[{"class":"one","site":[{"english":"twenty"}, {"english":"fouty"},{"english":"three"}]}]}
CSV.open("product.csv", 'wb') do |f|
productHash = products
if productHash.haskey("results")
productHash["results"].each do |p|
if p.haskey("site")
p["site"].each do |s|
f << s["english"]
end
else
f << "English not found"
end
else
f << "results not found"
end
上面的程序打印出下面的样式
twenty
foutrty
three
我希望将其打印为
twenty fourty three
我还需要在每个结果散列末尾换行,因为我有多个散列
【问题讨论】: