lib/cartesian_iterator.rb in Cartesian-0.2.3 vs lib/cartesian_iterator.rb in Cartesian-0.3.0
- old
+ new
@@ -1,15 +1,20 @@
-class CartesianIterator
+require 'grid_search'
+
+class CartesianIterator
+
+ include GridSearch
+
def initialize(foo, bar)
@lists = []
@tot_iter = 1
x(foo)
x(bar)
end
def x(other)
- @lists << other.to_a
+ @lists << other.to_a.dup
@tot_iter *= @lists[-1].size
self
end
def each
@@ -39,10 +44,11 @@
def to_a
array = []
self.each {|*element| array << element }
array
- end
+ end
+
end
module Iterable
def start
@next_index = -1