On Fri, 06 Apr 2007 10:21:01 -0700, srinsriram wrote:

> On Apr 6, 6:05 am, Robert Klemme <shortcut... / googlemail.com> wrote:
>> On 06.04.2007 11:00, Dipesh Batheja wrote:> Hi,
>> > Is there any instance method in Ruby for Date type, to find previous
>> > date. For example if I have date - "04/05/07" in an object "date",
>> > then something like "date.previous" returns me date - "04/04/07".
>>
>> $ irb -r date
>> irb(main):002:0> Date.today.to_s
>> => "2007-04-06"
>> irb(main):003:0> (Date.today - 1).to_s => "2007-04-05"
>> irb(main):004:0>
>>
>>         robert
> 
> I just noticed that whitespace near the -1 makes a difference in the
> evaluation in irb. is this expected?
> 
> irb(main):006:0> (Date.today -1).to_s => "2007-04-06"
> 
> irb(main):008:0> (Date.today - 1).to_s => "2007-04-05"

Yeah. The first way passes the value -1 as a parameter to Date.today.
The second way does math.

Ruby has lots of ambiguous operators like that (<< versus <<HEREDOC for 
example), your best strategy is to always put whitespace around your 
binary operators.

--Ken

-- 
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/