From: Kristof Bastiaensen Date: 2004-04-25T08:44:04+09:00 Subject: Re: Propose Range.new(..., &succ) On Sun, 25 Apr 2004 02:20:03 +0900, Jeff Mitchell wrote: > The other day I had > > (5..8).map { |x| > # stuff > }.other_stuff > > and at some point I wanted x to be in increments of 0.5. What to do? > Well I could be silly and define Float#succ. Short of that, I need to > change the code to either > > accum = [] > 5.step(8, 0.5) { |x| > accum << > # stuff > } > accum.other_stuff > > ... Hi, here is an alternative, using the incredible enum_for :-) (doesn't work with ruby-1.6). require "enumerator" 5.enum_for(:step, 8, 0.5).map { |x| #stuff }.other_stuff