From: AW Date: 2002-08-22T04:33:22+09:00 Subject: Re: the power of ruby puts "#{' ' * i}*" <-- That's a very nice way of doing it. I think sometimes i forget the "*Everything* is an object" concept. ;) >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 >