Rakshith Venkatesh
Rakshith Venkatesh

Reputation: 7

Ruby | DateTime

I was working with a ruby script to push stats into a time series kairos db and encountered the 'Datetime' class in ruby.

My question is does DateTime.now differ from DateTime.now()?

And if it does, can I get an example of their outputs?

Upvotes: 0

Views: 92

Answers (2)

gd_silva
gd_silva

Reputation: 1025

There is no difference between DateTime.now and DateTime.now(). Parentheses are optional in method calls in Ruby.

You can check some documentation about calling methods in Ruby here.

Example of both calls returning the exactly same result:

(local dev):0> DateTime.now
=> Thu, 14 May 2020 16:52:11 +0100

(local dev):0> DateTime.now()
=> Thu, 14 May 2020 16:52:15 +0100

Upvotes: 1

Aetherus
Aetherus

Reputation: 8898

No differences. They are the same method call. In Ruby, you can call any method with or without parentheses. And there's no "public fields" in Ruby, only public methods, so the only thing you can "dot" is methods.

Upvotes: 1

Related Questions