TheMouseMan TheMouseMan - 1 year ago 120
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]}"

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

3 4
5 6

Answer Source

try this:

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download