From: "Peña, Botp" Date: 2007-12-14T10:39:31+09:00 Subject: Re: Simple method and block. foo.times From: Stefano Crocco [mailto:stefano.crocco@alice.it] # If you want to include both 0 and 9, you can use upto instead # of times: yes, and the fun part of ruby is that you can create your own and be creative as much as you like, too; a simple example irb(main):025:0> class Integer irb(main):026:1> def mytimes start=0,inc=1 irb(main):027:2> x=start irb(main):028:2> cnt=self irb(main):029:2> while cnt > 0 irb(main):030:3> yield x irb(main):031:3> x+=inc irb(main):032:3> cnt-=1 irb(main):033:3> end irb(main):034:2> end irb(main):035:1> end => nil irb(main):036:0> 9.mytimes{|x| p x} 0 1 2 3 4 5 6 7 8 => nil irb(main):037:0> 9.mytimes(1){|x| p x} 1 2 3 4 5 6 7 8 9 => nil irb(main):038:0> 9.mytimes(2){|x| p x} 2 3 4 5 6 7 8 9 10 => nil irb(main):039:0> 9.mytimes(2,2){|x| p x} 2 4 6 8 10 12 14 16 18 => nil irb(main):040:0> 9.mytimes(2,-2){|x| p x} 2 0 -2 -4 -6 -8 -10 -12 -14 => nil irb(main):041:0> 9.mytimes(2,0){|x| p x} 2 2 2 2 2 2 2 2 2 => nil irb(main):042:0> kind regards -botp