From: Pit Capitain Date: 2006-08-16T05:57:24+09:00 Subject: Re: problem with date.succ Russ Pridemore schrieb: > I'm having difficulty with a small program I'm writing dealing with > dates. I've written the calendar class below. It works just fine > when calling getMonth for all months EXCEPT NOVEMBER. Interrupting > the call while in irb shows that it is busy in the reduce method of > Rational, called from Date. Any ideas? > > (...) > > def getMonth(mo) > dt = Date.new(@year, mo, 1) > i = dt.month > list = Array.new > while i != (mo+1) % 12 > wk = getWeek(dt.month, dt.day) > dt = wk[6].succ > i = dt.month > list.push(wk) > end > list > end > > (...) Russ, for November, "mo" is 11, and "(mo+1) % 12" is zero, but "dt.month" and "i" are always in the range (1..12), so you've got an endless loop. Replace the line while i != (mo+1) % 12 with next_month = mo % 12 + 1 while i != next_month and at least the loop should work as you expect. Regards, Pit