From: Robert Klemme on
2010/3/25 Rob Biedenharn <Rob(a)agileconsultingllc.com>:
>
> On Mar 24, 2010, at 11:35 PM, Alex Baranosky wrote:
>
>> I want to be able to have an object extend Enumerable in Ruby to be an
>> infinite list of Mondays (for example).
>>
>> So it would yield: March 29, April 5, April 12...... etc
>>
>> How can I implement this in Ruby?
>
> require 'date'
> class Mondays
>  include Enumerable
>
>  def initialize(starting=Date.today)
>    @monday = starting
>    @monday += 1 until @monday.wday == 1
>  end
>
>  def succ
>    @monday += 7
>  end

IMHO you are abusing #succ here since it is intended to return the
next element _of the same class_. Either you make it return self
which I would also consider not too safe because the instance does not
change or you change the design and move it to another class.

Here's my generic solution.

http://gist.github.com/343387

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/