From: Kirk Haines Date: 2005-08-02T20:27:22+09:00 Subject: Re: (mis)?use of method_missing On Tuesday 02 August 2005 1:52 am, Ben Stephens wrote: > > 6.days_from_now > > 345.days_from_now > > > > - Jamis > > Ooh, I like that, thanks. This sort of thing is very useful. irb(main):004:0> a = 4.days.ago => Fri Jul 29 05:08:19 MDT 2005 irb(main):005:0> b = a.from_now(1.week) => Fri Aug 05 05:08:19 MDT 2005 irb(main):006:0> c = 2.weeks.since(b) => Fri Aug 19 05:08:19 MDT 2005 Another thing that I have found very useful is adding some simple methods to Date and DateTime to support easy conversions between all three (Time, DateTime, Date) and to support this same family of actions on all of them. irb(main):015:0> a = 3.days.from_now.to_datetime => # irb(main):016:0> b = a.ago(1.week) => # irb(main):017:0> b.to_time => Fri Jul 29 05:25:20 MDT 2005 irb(main):018:0> b.to_date.to_s => "2005-07-29" irb(main):019:0> b.last_month.to_s => "2005-06-29T05:25:20Z" irb(main):020:0> b.last_month.to_time => Wed Jun 29 05:25:20 MDT 2005 irb(main):021:0> b.next_month.to_time => Mon Aug 29 05:25:20 MDT 2005 Makes working with dates and times a breeze. Kirk Haines