okkezSS
November 18, 2010, 8:46am
1
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 S. [email protected]
To: [email protected] (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 S…
2010/11/18 Eva [email protected]
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.
Eva
November 18, 2010, 9:03am
2
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
Eva
November 18, 2010, 9:18am
3
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 S…
2010/11/18 Eva [email protected]
Eva
November 18, 2010, 9:46pm
4
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)