|
Data Structures and Algorithms
with Object-Oriented Design Patterns in Ruby |
class Enumerator < Object
abstractmethod :reset
abstractmethod :current
abstractmethod :moveNext
end
The reset method ``resets'' the enumerator to the the first
element of the container.
The current method returns the current element or nil
if there are no more elements to enumerate.
The moveNext advances the enumerator to the next element.
Given an enumerator e from some container c, the contents of c can be printed like this:
e.reset
while not e.current.nil?
print e.current, "\n"
e.moveNext
end
Devise a wrapper class to encapsulate a Ruby iterator
and provide the functionality of a C# enumerator.