From: Mathieu Bouchard Date: 2000-10-16T10:59:48+09:00 Subject: [ruby-talk:5556] Re: 2 ideas from Haskell > matju considers: > > skip(2) makes range call .succ.succ instead of .succ; but > > with skip(1000) > > this may be an issue; so why not use .+ instead of .succ ? what about > > negative skips, and how should they be handled? > While you have pretty good idea here, don't forget that .succ is has been > chosen so that you can go over strings and String.+ wouldn't be so useful Ok, then let's define this: class Object def succ_many(n) (1..n).inject(self) {|a,b| a.succ } end end (assuming that the faq's Enumerable#inject is in Ruby, which it should be, and that the given object has succ defined.) Then StepRange could use Object#succ_many, and any class may redefine it for performance, e.g. class Integer def succ_many(n) self+n end end > In any event, we shouldn't forget > 1.step(10,2) { |i| print i, " " } #=> 1 3 5 7 9 Well, like for "for..in" and Integer#upto I don't care so much, and won't bother using them, as Enumerable#each, Range#each, and StepRange#each provide equivalent functionality. matju