R
Roshan James
I have been wondering is there is a way to do this. Can I have two
itertors working in lock-step - ie, can I have both of them return a
value each into the same loop body ?
a = [1, 2, 3, 4]
b = [5, 6, 7, 8]
a.each {|a1|
b.each {|b1|
# this nests the call to b inside a
}
}
Is there someway I can do something like -
a = [1, 2, 3, 4]
b = [5, 6, 7, 8]
(a.each, b.each) {|a1, b1|
#so that I get one value from a and one from b
}
I hope I have made the idea clear, the above syntax is only illustrative
of what I mean.
This is possible in python because the iterators are fundamentally
objects that require an explicit next() call and are not bound to the
the loop body/block by syntax as in ruby.
Thanks in advance,
Roshan
itertors working in lock-step - ie, can I have both of them return a
value each into the same loop body ?
a = [1, 2, 3, 4]
b = [5, 6, 7, 8]
a.each {|a1|
b.each {|b1|
# this nests the call to b inside a
}
}
Is there someway I can do something like -
a = [1, 2, 3, 4]
b = [5, 6, 7, 8]
(a.each, b.each) {|a1, b1|
#so that I get one value from a and one from b
}
I hope I have made the idea clear, the above syntax is only illustrative
of what I mean.
This is possible in python because the iterators are fundamentally
objects that require an explicit next() call and are not bound to the
the loop body/block by syntax as in ruby.
Thanks in advance,
Roshan