On Wed, Aug 21, 2002 at 05:30:53AM +0900, AW wrote: > As i get better writing ruby scripts (im pretty new), I often wonder > if im not exploiting the power of the language or that i'm casting > precedural language ideas onto my ruby scripts. I have here a little C > program that would like some of you to Rubi-tize if possible, so that > i can see how some of you that really know the language use it. I thought it might be interesting to write an iterator: WIDTH=78 def do_dot(i) puts "#{' ' * i}*" sleep 0.01 end def up_and_down(low, high) low.upto(high-1) do |i| yield i end high.downto(low+1) do |i| yield i end end loop do up_and_down(0, WIDTH) do |i| do_dot(i) end end The idea here is to separate what happens on each iteration from the iterating itself, and perhaps to be able to re-use the iterator somewhere else. I also added a sleep, because otherwise the stars jump around a bit too much in my terminal (Eterm). Paul