Effect of leaving space after '-' in Ruby expression

date, math, ruby, ruby-on-rails

Solution

What actually happens is this:

Date.today(-29.days) # => Fri, 07 Feb 2014

`today` has an optional parameter called `start`, which defaults to `Date::ITALY`.

An optional argument the day of calendar reform (start) as a Julian day number, which should be 2298874 to 2426355 or -/+oo. The default value is Date::ITALY (2299161=1582-10-15).

Passing `-29.days` to `today` apparently has no effect.

Whereas:

Date.today + -29.days # => Thu, 09 Jan 2014

Which is the same as:

Date.today - 29.days # => Thu, 09 Jan 2014

Problem

Today I was trying something out in my Rails console and this happened, ``` 2.0.0p247 :009 > Date.today -29.days => Fri, 07 Feb 2014 2.0.0p247 :010 > Date.today - 29.days => Thu, 09 Jan 2014 ``` I am pretty baffled. I can see that I am missing something basic. But it just inst striking my mind! Could anyone explain why this is happening?

Original source