From: Trans Date: 2008-03-15T05:32:53+09:00 Subject: Re: next(n), succ(n) ? On Mar 14, 3:45 pm, Chris Cummer wrote: > On 14-Mar-08, at 9:25 AM, Trans wrote: > > >> It might be useful in some cases as an optimization. For instance in > >> Integer: > > >> def succ(n=1) > >> self + n > >> end > > Could you elaborate on how this is an optimization? This functionality > seems to directly contradict the documented purpose of succ()/next() > so I'm not a fan of changing it as-is. > > However I can see a use for this functionality as an additional method > on the Integer class, perhaps as step() > > class Integer > def step(n=1) > self + n > end > > end Yes, that's close. #succ's main use is with Range. Range#step, for instance, would be able to take advantage of this parameter and thus potentially avoid iterating over pointless executions. Right now Range actually has special-case code just for Integer or String sentinels in order to optimize these types of Range iterations (this is known to put limitations on the potential uses of Range). By allowing the #succ method to handle the optimizations instead, Range could reduce it's exception coding, becoming more versatile, and other "rangeable" objects (eg. Date) could benefit from optimizations as well. T.