From: "Skye Shaw!@#$" Date: 2009-06-24T02:10:33+09:00 Subject: Re: Is it the ruby way to implement #downto On Jun 23, 8:36 am, Li Chen wrote: > Hi all, > > I wonder if the following code is the ruby way to implement > Integer#downto. > ####################### > class Integer >   def my_downto(final=2) >     for i in (final..self).to_a.reverse >       yield i >       end >    end >  end > >  10.my_downto(-1) do |i| puts i end Well, I'd hope that creating 3 unnecessary objects wouldn't be deemed the Ruby way :^) Most code I've seen would use each() instead of for i in (). Each is faster anyways. Why not use the bastardized C way: class Integer   def my_downto(final=2) i = self while i >= final yield i i-=1 end end end I don't believe the Ruby community has shunned the idea of writing C in ruby have they? -Skye