54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/cartesian_iterator.rb', line 54
def each
return false if @tot_iter < 1
elems = []
for list in @lists
elems << list.restart_and_raw_next
end
if RUBY_VERSION <= '1.9.1'; yield(*elems.map {|x| x }); else; yield(*elems); end
last_list_index = @lists.size-1
n = last_list_index
loop do
if !@lists[n].done?
elems[n] = @lists[n].raw_next
if RUBY_VERSION <= '1.9.1'; yield(*elems.map {|x| x }); else; yield(*elems); end n = last_list_index
next
elsif n > 0
elems[n] = @lists[n].restart_and_raw_next
n -= 1
else
return true
end
end
end
|