Time.today?

Whats are the respective Ruby versions? Time.today exists on 1.8.7,
but not 1.9.1 (or 1.8.6 to my knowledge)

You can do something like this (utilizing a Rails time method):

class Time
  def self.today
    Time.now.beginning_of_day
  end
end

Time.today

=> Mon Aug 31 00:00:00 +1200 2009

Regards
Kieran

Time has no today method, today is a Date method added by rails, as in
Date.today.

The method that looks like the same in time is Time.now.

Date.today is part of Ruby standard library (not added by Rails).

jeremy

Hi, here’s my results for the various Ruby implementations:

Ruby 1.8.6:

Time.now

=> Sun Aug 30 13:49:32 -0700 2009

Time.today

NoMethodError: undefined method `today’ for Time:Class

from (irb):2

Date.today

=> Sun, 30 Aug 2009

quit

Ruby 1.8.7:

Time.now

=> 2009-08-30 13:51:31 -0700

Time.today

NoMethodError: undefined method `today’ for Time:Class

from (irb):2

from /opt/local/bin/irb:12:in `<main>'

quit

Ruby 1.9.1:

Time.now

=> 2009-08-30 13:54:31 -0700

Time.today

NoMethodError: undefined method `today’ for Time:Class

from (irb):2

from /opt/local/bin/irb:12:in `<main>'

quit

Good luck,

-Conrad

What does the RUBY_VERSION say?

It looks like you accidentally ran the wrong IRB when testing this
out, as your Ruby "1.8.7" and 1.9.1 are both the same executable (/opt/
local/bin/irb).

But Keiran's suggestion isn't bad, might want to work a
method_defined? in with that though.

Hi, it’s actually two different machines.

-Conrad

> Hi, here's my results for the various Ruby implementations:

> Ruby 1.8.6:

> >> Time.now

> => Sun Aug 30 13:49:32 -0700 2009>> Time.today

> NoMethodError: undefined method `today' for Time:Class
> from (irb):2>> Date.today

> => Sun, 30 Aug 2009

> >> quit

> Ruby 1.8.7:

> >> Time.now

> => 2009-08-30 13:51:31 -0700>> Time.today

> NoMethodError: undefined method `today' for Time:Class
> from (irb):2
> from /opt/local/bin/irb:12:in `<main>'

> >> quit

> Ruby 1.9.1:

> >> Time.now

> => 2009-08-30 13:54:31 -0700>> Time.today

> NoMethodError: undefined method `today' for Time:Class
> from (irb):2
> from /opt/local/bin/irb:12:in `<main>'

> >> quit

> Good luck,

> -Conrad

What does the RUBY_VERSION say?

It looks like you accidentally ran the wrong IRB when testing this
out, as your Ruby "1.8.7" and 1.9.1 are both the same executable (/opt/
local/bin/irb).

But Keiran's suggestion isn't bad, might want to work a
method_defined? in with that though.

And this is me speaking apparently too soon

irb(main):006:0> RUBY_VERSION
=> "1.8.7"
irb(main):007:0> Time.today
NoMethodError: undefined method `today' for Time:Class
        from (irb):7
irb(main):008:0>

RUBY_VERSION

=> "1.8.7"

Time.today

=> Sun Aug 30 00:00:00 -0400 2009

So a gem must be adding this somewhere, I'm too lazy to look where
right now though

As someone told me before, I need to Google more :\