I understand you're fairly new to Ruby, AW, but I must give you some guidance
here.  As cool as <<puts "#{' ' * i}*">> is, the main point of Paul's program
was the iterator.  The fact that his method "up_and_down" simply counts up and
down, and is completely independent of what is being done with that count.
That is good design, and highlights Ruby as a good language.

I think you should thank Paul for imparting that lesson ;)

Cheers,
Gavin

----- Original Message -----
From: "AW" <sturmpanzer / metacrawler.com>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Thursday, August 22, 2002 5:33 AM
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
> >