From: "Peña, Botp" Date: 2007-12-14T12:22:09+09:00 Subject: Re: Simple method and block. foo.times From: Bernardo Monteiro Rufino [mailto:bermonruf@gmail.com] # class Integer # def mytimes(start=0, inc=1, &block) # start.step(start + (self * inc) - 1, inc, &block); ah, indeed; and as always, any refactoring/change must pass the test.. irb(main):011:0> 0.mytimes(-1,-1){|x| p x} -1 -2 => -1 irb(main):012:0> 1.mytimes(-1,-1){|x| p x} -1 -2 -3 => -1 irb(main):013:0> 2.mytimes(-1,-1){|x| p x} -1 -2 -3 -4 => -1 irb(main):014:0> 2.mytimes(-1,0){|x| p x} ArgumentError: step can't be 0 from (irb):3:in `step' from (irb):3:in `mytimes' from (irb):14 from :0 btw, i do not like the way ruby arranges it's params for #step. I prefer the step/inc arg to be the first arg since it reads clearly. eg, instead of 1.step 10, 2 i like 1.step 2, 10 reads clearly, and the step/inc is emphasize. kind regards -botp