Why is the Ruby Date class automatically loading, but DateTime not?

Using IRB, why are the Date and Time classes loaded automatically, but DateTime is not? I need require 'date' , it does not make sense to me, because I thought that both Date and DateTime used the standard library 'date' ?

 ruby-1.9.2-p290 :001 > Date => Date ruby-1.9.2-p290 :002 > Time => Time ruby-1.9.2-p290 :003 > DateTime NameError: uninitialized constant Object::DateTime from (irb):3 from /Users/kamilski81/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>' ruby-1.9.2-p290 :004 > require 'date' => true ruby-1.9.2-p290 :005 > require 'date' => false ruby-1.9.2-p290 :006 > DateTime => DateTime 
+42
ruby
Mar 14 '12 at 15:33
source share
3 answers

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 seems to me that this is an irb problem that automatically loads the β€œdate”.

0
Mar 14 2018-12-12T00:
source share

In the IRB, include this line: require 'date' , then you can 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 
+33
Jul 26 '13 at 19:25
source share

Worked for me on first initialization using require 'date' .

+3
Apr 18 '16 at 13:00
source share



All Articles