Date/DateTime need to be required and aren’t automatically loaded.
require ‘date’
now = DateTime.now
It is part of the Ruby ‘standard library’ but you do still need to
require a library before using it.
If you are not sure if a method is available, that is, you don’t know
if it has been required, use irb.
in irb try the method. Error message? then try require ‘library_name’
and it will return true on success, false on failure.
If it returns false, you might have mistyped the name, or path to the
library.
That may mean it’s loading all those libraries on windows even if you
don’t need them…
You might run a test to see if methods from various libraries are
available.
OK, that solves it - but interestingly, a require ‘date’ is
not necessary when running under Windows (both in the native and
cygwin build of Ruby).
That may mean it’s loading all those libraries on windows
even if you
don’t need them…
You might run a test to see if methods from various libraries are
available.
I wonder whether this is really the “official” definition of Ruby that
date.rb must be required explicitly. On Linux, it isn’t necessary
either,
and at least the Ruby books I have access to (“The Ruby Way” by Hal
Fulton
and “The Ruby Cookbook” by Richardson and Carlson) don’t mention a
require ‘date’ when discussing the Date and DateTime classes…
Ronald
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.