【发布时间】:2018-05-31 14:06:40
【问题描述】:
对 Ruby 和一般编码来说非常陌生。我正在尝试遍历二维数组,但无法弄清楚。这是我所拥有的:
--使用循环在不同的行上打印出每个人的不同自我。
--布鲁斯·韦恩,又名蝙蝠侠
people = [
["Bruce", "Wayne", "Batman"],
["Selina", "Kyle", "Catwoman"],
["Barbara", "Gordon", "Oracle"],
["Terry", "McGinnis", "Batman Beyond"]
]
index = people[0][0]
first_name = people[0][0]
last_name = people[0][1]
hero_name = people[0][2]
4.times do
puts first_name + " " + last_name + "," " " + "a.k.a" " " + hero_name
index = index + 1
end
它确实打印了第一行,但随后引发了错误:
Bruce Wayne, a.k.a Batman
# `+': no implicit conversion of Integer into String (TypeError)
【问题讨论】:
-
"," " "- 我认为高级 Ruby ;-)
标签: ruby