Why is Ruby's Date class automatically loaded but DateTime is not?

Solution 1:

In IRB, include this line: require 'date' then you will be able to use DateTime.

irb(main):000:0> DateTime.class
NameError: uninitialized constant DateTime
        from (irb):0
        from /path/to/ruby/irb:12:in '(main)'
irb(main):001:0> require 'date'
=> true
irb(main):002:0> DateTime.class
=> Class

Solution 2:

Worked for me when first initializing with require 'date'.

Solution 3:

Being a little more curious, I tried:

$ ruby -e 'puts DateTime.class'
-e:1:in `<main>': uninitialized constant Object::DateTime (NameError)
[~, kamilski81@mac]
$ ruby -e 'puts Date.class'
-e:1:in `<main>': uninitialized constant Object::Date (NameError)
$ ruby -e 'puts Time.class'
Class

So it makes me think that it's an irb issue that automatically loads 'date'.