of course your right, my variant leaves out the first element. what's actually the sense behind returning self? On 9/1/05, Brian Schröäer <ruby.brian / gmail.com> wrote: > On 01/09/05, Philipp Huber <huber.philipp / gmail.com> wrote: > > actually i did test it with a queue filled with a few elements. as you > > said the condition for the while loop should be testet at the > > beginning, otherwise nil could be returned. > > so my code looks like this: > > > > def each > > node=@head > > while node=node.next > > yield node.content > > end > > end > > > > do you have an example for the second remark, as i don't quite > > understand what you mean > > > > thanks, > > philipp > > > > > > Sorry for posting something that untested. But as I look again you > continue to have bugs in your code. > > You are missing the first element. The following should work and also > return self. That allows you to do something like the following: > > queue.each do | element | element.seen += 1 end.each do | element | > puts element end > > Beware that the above example does not make that much sense, but I do > not have a better example ready. > > def each > node=@head > while node > yield node.content > node=node.next > end > self > end > > hope to help > > Brian > > -- > http://ruby.brian-schroeder.de/ > > Stringed instrument chords: http://chordlist.brian-schroeder.de/ > >