1 # A class which provides a method `each' to be used as an Enumerable
8 def initialize(obj,iter, *args)
11 @iterator = @object.method(iter.to_sym)
16 @iterator.call(*@args, &block)
20 def each_cons(n, &block)
23 while elements.size > 0 do
24 array << elements[0,n] if elements[0,n].size == n
27 array.each { |set| yield set }
32 Enumerable::Enumerator.new(self, :each_cons, n)
35 def each_slice(slice_size, &block)
39 if a.length == slice_size
44 yield a if a.length > 0
48 Enumerable::Enumerator.new(self, :each_slice, n)
52 Enumerable::Enumerator.new(self, :each_with_index)
57 def enum_for(method, *args)
58 Enumerable::Enumerator.new(self,method,*args)