Mark Hubbart
5/10/2005 8:38:00 PM
On 5/10/05, John Lam <drjflam@gmail.com> wrote:
> Thanks, Mark!
>
> The self >> 1 line is um, rather mysterious to me. How does that skip by months?
That's the bitshift operator, which is often used in classes for other
purposes. In the Date, it's used to add and subtract months:
Date.today << 2 will give you 2 months ago today, while Date.today >>
1 will give you next month today. I guess they decided to use it for
that because "+" and "-" were already taken, used for adding and
subtracting days.
Ranges use #succ (successor) to get the next object in a series. By
redefining #succ to return self >> 1 (self + 1 month), we get a range
of dates that skips by months rather than days.
cheers,
Mark