From: George Ogata Date: 2002-08-07T03:01:44+09:00 Subject: Re: Super-iterator? Joseph Erickson wrote: > I like it. > > What about a 'multilpe_of?' function. I hope this makes sense: > > You could have a multiple_of? function so you could say multiple_of?(3) > and it would give you every third iteration. You could also add another > parameter that would subtract back that number like multiple_of?(3,2) > would give you 1,4,7,10 etc. That would make even? be multiple_of?(2) > and odd? be multiple_of?(2,1) > > def multiple_of?(multiple,back) > @count_ % multiple == back > end > > If you wanted to generalize it further, you could feed it a block which evaluates the ith desired index. e.g., {|i|2*i} for evens, {|i|2*i+1} for odds, {|i|n*i} for every nth, {|i|f(i)} for something hairy, ...