From: Kero Date: 2005-08-02T21:56:05+09:00 Subject: Re: (mis)?use of method_missing >> > 6.days_from_now >> > 345.days_from_now >> Ooh, I like that, thanks. I don't. What does an Integer have to know about times and dates? irb(main):001:0> 3 + Time.now TypeError: Time can't be coerced into Fixnum from (irb):1:in `+' from (irb):1 irb(main):002:0> Time.now + 3 => Tue Aug 02 14:20:43 CEST 2005 > This sort of thing is very useful. > irb(main):004:0> a = 4.days.ago >=> Fri Jul 29 05:08:19 MDT 2005 Minute = 60 Hour = 60 * Minute Day = 24 * Hour Week = 7 * Day ### Disadvantages: # - Can't spell out month # - need different constants in Time/Date, etc. # but then, 3.days.from(Time.now) and 3.days.from(Date.today) # is going to stink too, unless you introduce a Day or Duration class... ### Advantages: # - no 'readable' methods polluting Integer namespace. a = Time.now - 4*Days > irb(main):005:0> b = a.from_now(1.week) >=> Fri Aug 05 05:08:19 MDT 2005 b = a + Week # I'm much shorter here and I don't have the confusing word "now" in the # code. > irb(main):006:0> c = 2.weeks.since(b) >=> Fri Aug 19 05:08:19 MDT 2005 c = b + 2*Week [snip] > 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 please use "next" and "prev" (as well as "last" and "first" :P ) in pairs. if anything, last_month should be a class method, like Time.now() Bye, Kero.