From: Jacob Fugal Date: 2006-02-01T08:48:21+09:00 Subject: Re: [RCR] Numeric#of On 1/31/06, Yukihiro Matsumoto wrote: > On 2/1/06, ara.t.howard@noaa.gov wrote: > > harp:~ > irb > > irb(main):001:0> class Numeric; def of(&b) Array::new(self).map(&b) end; end > > => nil > > > > irb(main):002:0> 42.of{ String::new } > > => ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""] > > Using my not-yet-committed 1.9, you can type > > 42.times.collect{String::new} > > to get the same result. Cool! So does times still work with a block? I'm assuming that it switches behavior, being a generator itself if a block is present, and creating a generator object (which includes Enumerable) when no block is provided. Eg. (simplified): class Numeric def times( &blk ) generator = # some code to create the generator # that runs from 0 to self-1 generator.each &blk if block_given? generator end end If that's the case, this is awesome! Jacob Fugal