On Oct 20, 2009, at 1:14 AM, Jian Lin wrote:

> Rob Biedenharn wrote:
>
>> irb> class Integer
>>        def countdown
>>          self.downto(1){|i|yield i}
>>        end
>>      end
>> => nil
>> irb> 35.countdown {|i| print i, ' '}; puts "Boom!"
>> 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13
>> 12 11 10 9 8 7 6 5 4 3 2 1 Boom!
>
> yup, that's similar to what i was looking for.  And 35.times doesn't
> have any mechanism to count down i guess, not like
>
> for i = 35 to 1 step -1
>  do something
> next
>
> --  
> Posted via http://www.ruby-forum.com/.
>


Just use Integer#step if that's how you want to think about it:

irb> 35.step(1,-1) {|i| print i,' '}; puts "Ha!"
35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13  
12 11 10 9 8 7 6 5 4 3 2 1 Ha!
=> nil

-Rob

Rob Biedenharn		http://agileconsultingllc.com
Rob / AgileConsultingLLC.com