From: Todd Date: 2005-07-28T06:36:01+09:00 Subject: Re: add_weekdays method Chris Roos wrote: > Hi, > > I've just spent some time looking at an add_weekdays method on the Date > class. > > My implementation is as follows. > > class Date > def add_weekdays(days) > new_date = self > while days > 0 > new_date += 1 > days -= 1 unless (new_date.wday == 6 || new_date.wday == 0) > end > new_date > end > end > > I'm interested to know whether I've a) wasted my time because I could > have achieved the same thing with an already available object/method b) > commited any ruby sins and c) whether there are much better ways of > implementing this? > > Chris Looks like you want to skip weekends. I might do it this way... class Date def add_weekdays(days) new_date = self days.times { new_date += ( new_date.wday == 6 ? 3 : 1 ) } end end But your way is just fine. Todd