VERY new to Ruby and coding in general. I'm trying to loop through two dimensional arrays but can't figure it out. Here's what I have:
--Use a loop to print out each person on separate lines with their alter egos.
--Bruce Wayne, a.k.a. Batman
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
It does print the first line but then raises an error:
Bruce Wayne, a.k.a Batman
# `+': no implicit conversion of Integer into String (TypeError)
"," " "– I consider that advanced Ruby ;-)