Time question

Thanks.
But why the dot for the method call can be ignored in this case?

Time.now.-(86400)
Time.now - 86400

the second has lost a "." before "-".

···

----- Original Message -----
From: Dhruva Sagar <dhruva.sagar@gmail.com>
To: ruby-talk@ruby-lang.org (ruby-talk ML)
Subject: Re: Time question
Date: 2010-11-18 15:29:51

Time.now.-(86400)

"- is the method here on the Time object that Time.now returns..."

--

Thanks & Regards,

Dhruva Sagar.

2010/11/18 Eva <eva54321@sina.com>

Hello,

Why Time.now - 86400 works?

but when I tried Time.now(-86400) it won't work.

I was thinking -86400 is an argument for the class method "now".

Thanks.

But why the dot for the method call can be ignored in this case?

Time.now.-(86400)
Time.now - 86400

the second has lost a "." before "-".

most operators are methods in ruby
Time.now - 86400 is syntactic sugar for Time.now.-(86400)

scroll down and look for "Operator Methods" in the language documentation
http://www.ruby-doc.org/docs/ProgrammingRuby/language.html

In Ruby everything is an object. When you do 1 + 2, you need to understand
and register (in your mind) the fact that both 1 & 2 here are objects
(Fixnum objects to be specific). Since everything is an object, they can
interact with each other only by means of methods. 1 + 2 == 1.+(2), the
syntax 1 + 2 is provided by Ruby for convenience sake, since we are used to
it, what is actually happening is the latter, i.e. 1.+(2)

···

--
Thanks & Regards,
Dhruva Sagar.

2010/11/18 Eva <eva54321@sina.com>

Thanks.
But why the dot for the method call can be ignored in this case?

Time.now.-(86400)
Time.now - 86400

the second has lost a "." before "-".

----- Original Message -----
From: Dhruva Sagar <dhruva.sagar@gmail.com>
To: ruby-talk@ruby-lang.org (ruby-talk ML)
Subject: Re: Time question
Date: 2010-11-18 15:29:51

Time.now.-(86400)

"- is the method here on the Time object that Time.now returns..."

--

Thanks & Regards,

Dhruva Sagar.

2010/11/18 Eva <eva54321@sina.com>

> Hello,

>

> Why Time.now - 86400 works?

>

> but when I tried Time.now(-86400) it won't work.

> I was thinking -86400 is an argument for the class method "now".

>

> Thanks.

>

Rohit Kumar wrote in post #962299:

But why the dot for the method call can be ignored in this case?

Time.now.-(86400)
Time.now - 86400

the second has lost a "." before "-".

most operators are methods in ruby
Time.now - 86400 is syntactic sugar for Time.now.-(86400)

which in turn can be made even more explicit:

  Time.send(:now).send(:-, 86400)

···

--
Posted via http://www.ruby-forum.com/\.