TheMouseMan TheMouseMan - 4 months ago 19
Ruby Question

ruby Array key pair value?

I am trying to pair up two key value pairs but I am unsure how to accomplish this. Below is what I have attempted:

struc = Array[(3,4),(5,6)]
for i in 0..1
puts "#{struc[i,i]}"
end


But my desired output is the following (which the previous code block does not produce):

3 4
5 6

Answer

try this:

arr = [[3,4],[5,6]]
arr.each do |(a,b)|
  puts "#{a} #{b}"
end

Also you array syntax (Array[(3,4),(5,6)]) is incorrect.