PDA

View Full Version : custom iterator


sheefo
September 15th, 2007, 02:17 PM
How can I make an iterator for my Linked List class?

I want to turn this code:
node = list.startnode
while node
puts node.data
node = node.next
end

Into something like this, so it is easy to loop through the list.
list.loop { | node | puts node.data }