From: Robert Dober Date: 2007-06-07T20:29:46+09:00 Subject: Re: What about a 'series' type? On 6/7/07, Peter Marsh wrote: Honestly I do not believe that the core is the place to put such things, furthermore I believe it is too specific a feature, a more general approach might have better chances to be fit for the core; Yet I do not think what follows is fit for the core either, but maybe you find it interesting or helpful: class Lazy def initialize init, op, *args @init = init @op = op @args = args.dup end def upto value return [] if value < 1 (2..value).inject([@init]){ |acc,| acc << acc.last.send( @op, *@args ) } end end # class Lazy 505/6 > irb -r lazy.rb irb(main):001:0> l = Lazy.new 1, :+, 2 => # irb(main):002:0> l.upto 5 => [1, 3, 5, 7, 9] irb(main):003:0> m = Lazy.new 2, :*, 3 => # irb(main):004:0> m.upto 4 => [2, 6, 18, 54] irb(main):005:0> Cheers Robert P.S. Implementations without #inject are theoretically possible ;) R. -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw