Re: Duration

Frederick Cheung
Wed, 22 Dec 2010 12:51:05 -0000

On Dec 21, 10:07 pm, Peter Vandenabeele
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:
> Frederick Cheung wrote in post #969871:

>
> I am actually curious how I could see from the object
> itself in a Rails context that it''s not "really" a
Fixnum,
> but an ActiveSupport::Duration object

ActiveSupport::Duration === foo would return true (or Fixnum === foo
would return false)


> Also, here I did use specific units (in-casu "days"),
> but still I had naively expected a different result
> on line 005.
>
> 004:0> weekend.seconds
> => 172800 seconds # this is correct
> 005:0> weekend.days
> => 172800 days # I had expected ''2'' or ''2
days''

a Duration object doesn''t have days (or seconds etc.) methods that
return the invidual components (the parts method does that), so when
you call days on it, it ends up calling days on its value in seconds.

>
> Thanks,
>
> Peter
>
> --
> Posted viahttp://www.ruby-forum.com/.