T
tsuraan
Suppose I have two arrays, one holding times, and the other holding
events corresponding to the times. I want to step through both arrays
at the same time. Is there an elegant way to do this? For example:
times = [ '1', '2', '3', '4', '5']
events = [ 'eat', 'sleep', 'eat', 'play', 'sleep' ]
times.size.times { |cnt|
puts times[cnt] + ": " + events[cnt]
}
That's not too pretty; at least, I think the times.size.times {block}
is ugly. Is there a way to join the arrays into an array of n-tuples
and step through them one tuple at a time? I'm a newby, and not
entirely sure what ruby builtins would make sense for this. Thanks!
events corresponding to the times. I want to step through both arrays
at the same time. Is there an elegant way to do this? For example:
times = [ '1', '2', '3', '4', '5']
events = [ 'eat', 'sleep', 'eat', 'play', 'sleep' ]
times.size.times { |cnt|
puts times[cnt] + ": " + events[cnt]
}
That's not too pretty; at least, I think the times.size.times {block}
is ugly. Is there a way to join the arrays into an array of n-tuples
and step through them one tuple at a time? I'm a newby, and not
entirely sure what ruby builtins would make sense for this. Thanks!