Date and DateTime on the Mac

I have installed ruby for Mac OS/X. Strangely, the classes Date and
DateTime
are not known:

NameError: uninitialized constant DateTime
        from (irb):1

At least some other classes (I tried File and Time) exist, so it is
not that the
installation were completely broken.

What could be the problem here?

Ronald

did you do a

   require 'date'

before trying to access Date or DateTime. They are not part of
the Core classes that are automatically defined when Ruby starts up.

···

On Aug 20, 2007, at 3:50 PM, Ronny wrote:

I have installed ruby for Mac OS/X. Strangely, the classes Date and
DateTime
are not known:

NameError: uninitialized constant DateTime
        from (irb):1

At least some other classes (I tried File and Time) exist, so it is
not that the
installation were completely broken.

What could be the problem here?

Date/DateTime need to be required and aren't automatically loaded.

require 'date'
now = DateTime.now

···

-----Original Message-----
From: Ronny [mailto:ro.naldfi.scher@gmail.com]
Sent: Monday, August 20, 2007 12:50 PM
To: ruby-talk ML
Subject: Date and DateTime on the Mac

I have installed ruby for Mac OS/X. Strangely, the classes Date and
DateTime
are not known:

NameError: uninitialized constant DateTime
        from (irb):1

At least some other classes (I tried File and Time) exist, so it is
not that the
installation were completely broken.

What could be the problem here?

Ronald

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.

···

On Aug 20, 2007, at 3:07 PM, Felix Windt wrote:

-----Original Message-----
From: Ronny [mailto:ro.naldfi.scher@gmail.com]
Sent: Monday, August 20, 2007 12:50 PM
To: ruby-talk ML
Subject: Date and DateTime on the Mac

I have installed ruby for Mac OS/X. Strangely, the classes Date and
DateTime
are not known:

NameError: uninitialized constant DateTime
        from (irb):1

At least some other classes (I tried File and Time) exist, so it is
not that the
installation were completely broken.

What could be the problem here?

Ronald

Date/DateTime need to be required and aren't automatically loaded.

require 'date'
now = DateTime.now

did you do a

   require 'date'

before trying to access Date or DateTime. They are not part of
the Core classes that are automatically defined when Ruby starts up.

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).

Ronald

···

--
Ronald Fischer <ronald.fischer@venyon.com>
Phone: +49-89-452133-162

Is this platform dependent? 'require' doesn't seem to be, er, required
on my SuSE system --

hassan@ceylon:~> ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [x86_64-linux]
hassan@ceylon:~> irb
irb(main):001:0> DateTime.now.to_s
=> "2007-08-20T14:14:31-07:00"
irb(main):002:0>

···

On 8/20/07, John Joyce <dangerwillrobinsondanger@gmail.com> wrote:

It is part of the Ruby 'standard library' but you do still need to
require a library before using it.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

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.

···

On Aug 21, 2007, at 4:05 AM, Ronald Fischer wrote:

did you do a

   require 'date'

before trying to access Date or DateTime. They are not part of
the Core classes that are automatically defined when Ruby starts up.

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).

Ronald
-- Ronald Fischer <ronald.fischer@venyon.com>
Phone: +49-89-452133-162

Be careful with irb. It has its own set of startup rules and behaviors that
are slightly different than Ruby itself. Try:

ruby -e 'puts DateTime.now.to_s'

Ruby's startup behaviour can also be changed if the RUBYOPT environment
variable is set.

On my installation irb shows 451 classes defined at startup while the Ruby
interpreter just shows 147 classes.

···

On Aug 20, 2007, at 5:12 PM, Hassan Schroeder wrote:

On 8/20/07, John Joyce <dangerwillrobinsondanger@gmail.com> wrote:

It is part of the Ruby 'standard library' but you do still need to
require a library before using it.

Is this platform dependent? 'require' doesn't seem to be, er, required
on my SuSE system --

hassan@ceylon:~> ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [x86_64-linux]
hassan@ceylon:~> irb
irb(main):001:0> DateTime.now.to_s
=> "2007-08-20T14:14:31-07:00"
irb(main):002:0>

> 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

···

--
Ronald Fischer <ronald.fischer@venyon.com>
Phone: +49-89-452133-162

Aha, that fails. Good to know -- thanks for the clarification.

···

On 8/20/07, Gary Wright <gwtmp01@mac.com> wrote:

Be careful with irb. It has its own set of startup rules and
behaviors that are slightly different than Ruby itself. Try:

ruby -e 'puts DateTime.now.to_s'

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

Good call, that's true, irb does require some things automatically.

···

On Aug 20, 2007, at 4:29 PM, Gary Wright wrote:

On Aug 20, 2007, at 5:12 PM, Hassan Schroeder wrote:

On 8/20/07, John Joyce <dangerwillrobinsondanger@gmail.com> wrote:

It is part of the Ruby 'standard library' but you do still need to
require a library before using it.

Is this platform dependent? 'require' doesn't seem to be, er, required
on my SuSE system --

hassan@ceylon:~> ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [x86_64-linux]
hassan@ceylon:~> irb
irb(main):001:0> DateTime.now.to_s
=> "2007-08-20T14:14:31-07:00"
irb(main):002:0>

Be careful with irb. It has its own set of startup rules and behaviors that
are slightly different than Ruby itself. Try:

ruby -e 'puts DateTime.now.to_s'

Ruby's startup behaviour can also be changed if the RUBYOPT environment
variable is set.

On my installation irb shows 451 classes defined at startup while the Ruby
interpreter just shows 147 classes.