"Hal Fulton" <hal9000 / hypermetrics.com> schrieb im Newsbeitrag
news:40594440.3000202 / hypermetrics.com...
> I did a little swapping of ideas with dblack on this. Now I'm
> opening discussion to anyone interested.
>
> I'm writing a little to-do manager (chiefly for my own use).
>
> I want to allow recurring tasks. Some of these will be simple, like
> "Every Monday." Others will be more complex, like "Every 2nd and 4th
> Friday." Some might not even be based on weeks or months at all, but
> might be like: "Every ten days, no matter what."
>
> There'd also be an option to give advance warning (N days) on each
> event.
>
> So the question becomes: Given a date (typically "today") and a list
> of recurring tasks, how do I determine which ones need to be displayed?

How about:

class Schedule < Hash
  def ===(time)
    each do |sym, val|
      case val
        when Enumerable
          return false unless val.include?( time.send(sym) )
        when nil
          # ignore
        else
          return false unless val == time.send(sym)
      end
    end

    true
  end
end


irb(main):017:0> sched = Schedule.new
=> {}
irb(main):018:0> sched[:year]=[2003,2004]
=> [2003, 2004]
irb(main):019:0>
irb(main):020:0* sched === Time.now
=> true
irb(main):021:0>
irb(main):022:0* sched[:year]=nil
=> nil
irb(main):023:0> sched === Time.now
=> true
irb(main):024:0>
irb(main):025:0* sched[:year]=[2005]
=> [2005]
irb(main):026:0> sched === Time.now
=> false
irb(main):029:0> sched[:year]=(2000..2010)
=> 2000..2010
irb(main):030:0> sched === Time.now
=> true

Regards

    robert