From: Joe Van Dyk Date: 2005-04-29T07:50:22+09:00 Subject: Re: stupid question On 4/28/05, James Edward Gray II wrote: > On Apr 28, 2005, at 4:18 PM, Dick Davies wrote: > > > rasputnik$ ri Numeric#step > > ----------------------------------------------------------- > > Numeric#step > > I the new version which I think is cool: > > ------------------------------------------------------------- Range#step > rng.step(n=1) {| obj | block } => rng > ------------------------------------------------------------------------ > Iterates over rng, passing each nth element to the block. If the > range contains numbers or strings, natural ordering is used. > Otherwise step invokes succ to iterate through range elements. The > following code uses class Xs, which is defined in the class-level > documentation. > > range = Xs.new(1)..Xs.new(10) > range.step(2) {|x| puts x} > range.step(3) {|x| puts x} > > produces: > > 1 x > 3 xxx > 5 xxxxx > 7 xxxxxxx > 9 xxxxxxxxx > 1 x > 4 xxxx > 7 xxxxxxx > But that only goes up, right?