Built-in vs. standard library

I'm confused about whether the Date class is built-in or in the
standard library.

I can use it without requiring it in irb, so that tells me it's built-in.
Pickaxe doesn't document it in the "Built-in Classes and Modules"
reference chapter.
Pickaxe does document a Date class in the "Standard Library" chapter.
Are there two different date classes?
Should I be able to determine this by looking at source files under
the lib/ruby/1.8 directory?
It's seems like those source files are all for standard library classes. True?

···

--
R. Mark Volkmann
Partner, Object Computing, Inc.

I'm confused about whether the Date class is built-in or in the
standard library.

It's a standard library.

I can use it without requiring it in irb, so that tells me it's built-in.

Na, that tells you that irb requires it somewhere. :slight_smile:

James Edward Gray II

···

On Feb 4, 2006, at 2:57 PM, Mark Volkmann wrote:

Actually, it's a little weirder than that. I've wondered about it myself:

irb(main):001:0> Date.methods(false)
=> ["zone_to_diff", "_parse", "_strptime"]
irb(main):002:0> Date.today
NoMethodError: undefined method `today' for Date:Class
        from (irb):2
irb(main):003:0> require 'date'
=> true
irb(main):004:0> Date.today
=> #<Date: 4907541/2,0,2299161>
irb(main):005:0> Date.methods(false)
=> ["jd_to_ajd", "ld_to_jd", "ordinal", "ajd_to_amjd", "new0", "jd",
"valid_ordinal?", "exist2?", "e
xist?", "jd_to_civil", "jd_to_wday", "gregorian_leap?",
"valid_commercial?", "parse", "new3", "os?",
"commercial_to_jd", "jd_to_mjd", "valid_civil?", "new",
"zone_to_diff", "jd_to_ordinal", "valid_jd?
", "commercial", "exist1?", "day_fraction_to_time", "jd_to_ld",
"julian_leap?", "today", "new2", "_p
arse", "existw?", "ordinal_to_jd", "amjd_to_ajd", "ns?",
"civil_to_jd", "ajd_to_jd", "valid_date?",
"new1", "_strptime", "jd_to_commercial", "mjd_to_jd", "strptime",
"exist3?", "time_to_day_fraction",
"leap?", "civil", "_load", "neww"]
irb(main):006:0>

···

On 2/4/06, James Edward Gray II <james@grayproductions.net> wrote:

On Feb 4, 2006, at 2:57 PM, Mark Volkmann wrote:

> I'm confused about whether the Date class is built-in or in the
> standard library.

It's a standard library.

> I can use it without requiring it in irb, so that tells me it's
> built-in.

Na, that tells you that irb requires it somewhere. :slight_smile:

Then why does this code run?

d = Date.new
puts "d is a #{d.class}"

This is telling me that there is a built-in Date class and there is
another one in the Standard Library.

ruby-doc.org documents a Date class under both the "Core API" and the
"Standard API". They look very similar, but not identical. As I said
earlier, pickaxe does not document it as a built-in.

Why do there seem to be two Date classes?

···

On 2/4/06, James Edward Gray II <james@grayproductions.net> wrote:

On Feb 4, 2006, at 2:57 PM, Mark Volkmann wrote:

> I'm confused about whether the Date class is built-in or in the
> standard library.

It's a standard library.

> I can use it without requiring it in irb, so that tells me it's
> built-in.

Na, that tells you that irb requires it somewhere. :slight_smile:

--
R. Mark Volkmann
Partner, Object Computing, Inc.

Just curious, what is your output from this code?

  p 1 if defined? Date
  require 'irb'
  p 2 if defined? Date
  require 'rubygems'
  p 3 if defined? Date

I just get 3 (which I think is expected). Do you require rubygems in your ..irbrc? or $RUBYOPTS?

···

On Sat, 04 Feb 2006 23:23:36 -0000, Mark Volkmann <r.mark.volkmann@gmail.com> wrote:

On 2/4/06, James Edward Gray II <james@grayproductions.net> wrote:

On Feb 4, 2006, at 2:57 PM, Mark Volkmann wrote:

> I'm confused about whether the Date class is built-in or in the
> standard library.

It's a standard library.

> I can use it without requiring it in irb, so that tells me it's
> built-in.

Na, that tells you that irb requires it somewhere. :slight_smile:

Then why does this code run?

d = Date.new
puts "d is a #{d.class}"

This is telling me that there is a built-in Date class and there is
another one in the Standard Library.

--
Ross Bamford - rosco@roscopeco.remove.co.uk

Mark Volkmann wrote:

  

I'm confused about whether the Date class is built-in or in the
standard library.
      

It's a standard library.

I can use it without requiring it in irb, so that tells me it's
built-in.
      

Na, that tells you that irb requires it somewhere. :slight_smile:
    
Then why does this code run?

d = Date.new
puts "d is a #{d.class}"

This is telling me that there is a built-in Date class and there is
another one in the Standard Library.

ruby-doc.org documents a Date class under both the "Core API" and the
"Standard API". They look very similar, but not identical. As I said
earlier, pickaxe does not document it as a built-in.

Why do there seem to be two Date classes?

--
R. Mark Volkmann
Partner, Object Computing, Inc.
  

Hi,

I wonder if you might have required rubygems at some point. Sifting through rubygems:
rubygems/open-uri.rb: require 'parsedate'
parsedate.rb: require 'date/format'

So if you've got RUBYOPT set to rubygems, you'll have required rubygems already. Try evaluating Date::MONTHNAMES. This constant is set in date.rb and not date/format.rb so if you've only required data/format then you'll have a chance to hear the uninitialized constant song.

Having required rubygems would explain the presence of the Date class in your ruby above.

Hope that helps. If anyone has a better idea of where the rogue Date might be coming from, I'd love to hear it.

Regards,
Matthew J. Desmarais

P.S. I just realized that you'll get a good idea of what (aside from core) is in your ruby by evaluating $". That's the array that holds the list of files that have been require'd.

···

On 2/4/06, James Edward Gray II <james@grayproductions.net> wrote:

On Feb 4, 2006, at 2:57 PM, Mark Volkmann wrote:

>>
>> > I'm confused about whether the Date class is built-in or in the
>> > standard library.
>>
>> It's a standard library.
>>
>> > I can use it without requiring it in irb, so that tells me it's
>> > built-in.
>>
>> Na, that tells you that irb requires it somewhere. :slight_smile:
>
> Then why does this code run?
>
> d = Date.new
> puts "d is a #{d.class}"
>
> This is telling me that there is a built-in Date class and there is
> another one in the Standard Library.
>

Just curious, what is your output from this code?

        p 1 if defined? Date
        require 'irb'
        p 2 if defined? Date
        require 'rubygems'
        p 3 if defined? Date

I get
1
2
3

I just get 3 (which I think is expected). Do you require rubygems in your
..irbrc? or $RUBYOPTS?

I'm running Ruby 1.8.4 under Windows XP. I don't have a RUBYOPTS
environment variable set and I get the result above when I put the
code in a file and run it with "ruby myfile.rb", so I guess the .irbrc
part doesn't matter.

···

On 2/4/06, Ross Bamford <rosco@roscopeco.remove.co.uk> wrote:

On Sat, 04 Feb 2006 23:23:36 -0000, Mark Volkmann > <r.mark.volkmann@gmail.com> wrote:
> On 2/4/06, James Edward Gray II <james@grayproductions.net> wrote:
>> On Feb 4, 2006, at 2:57 PM, Mark Volkmann wrote:

--
R. Mark Volkmann
Partner, Object Computing, Inc.

Good suggestion! I tried that and I see that "rubygems.rb" is being
loaded. I just don't know why that is happening. Is that something
that automatically happens when you are using the latest version of
the Windows One Click Installer? As was suggested earlier,
rubygems.rb ends up requiring parsedate.rb.

This still leaves the question of why ruby-doc.org documents the Date
class as being in the Core API.

···

On 2/4/06, Matthew Desmarais <desmarm@gmail.com> wrote:

P.S. I just realized that you'll get a good idea of what (aside from
core) is in your ruby by evaluating $". That's the array that holds the
list of files that have been require'd.

--
R. Mark Volkmann
Partner, Object Computing, Inc.

Mark Volkmann wrote:

P.S. I just realized that you'll get a good idea of what (aside from
core) is in your ruby by evaluating $". That's the array that holds the
list of files that have been require'd.
    
Good suggestion! I tried that and I see that "rubygems.rb" is being
loaded. I just don't know why that is happening. Is that something
that automatically happens when you are using the latest version of
the Windows One Click Installer? As was suggested earlier,
rubygems.rb ends up requiring parsedate.rb.
  

Very odd. I noticed that earlier in the thread that you said that you didn't have a RUBYOPTS environment variable set. The environment variable that will get you is actually RUBYOPT. Is it possible that you have this one set? If not then you can color me puzzled.

This still leaves the question of why ruby-doc.org documents the Date
class as being in the Core API.
  

Oh, that? I have no idea. :wink:

It probably shouldn't be though, eh?

···

On 2/4/06, Matthew Desmarais <desmarm@gmail.com> wrote:

Mark Volkmann wrote:

···

On 2/4/06, Matthew Desmarais <desmarm@gmail.com> wrote:

P.S. I just realized that you'll get a good idea of what (aside from
core) is in your ruby by evaluating $". That's the array that holds the
list of files that have been require'd.

Good suggestion! I tried that and I see that "rubygems.rb" is being
loaded. I just don't know why that is happening. Is that something
that automatically happens when you are using the latest version of
the Windows One Click Installer? As was suggested earlier,
rubygems.rb ends up requiring parsedate.rb.

This still leaves the question of why ruby-doc.org documents the Date
class as being in the Core API.

Because I run rdoc over the base set of lib files.

If there is a better way to do this, I would be happy to change.

(What I would prefer is a single set of API files that do not require one to know whether something is 'core' or 'std-lib'. )

James
--
James Britt

"The greatest obstacle to discovery is not ignorance, but the illusion of knowledge."
  - D. Boorstin

Mark Volkmann wrote:
>
>
>> P.S. I just realized that you'll get a good idea of what (aside from
>> core) is in your ruby by evaluating $". That's the array that holds the
>> list of files that have been require'd.
>
> Good suggestion! I tried that and I see that "rubygems.rb" is being
> loaded. I just don't know why that is happening. Is that something
> that automatically happens when you are using the latest version of
> the Windows One Click Installer? As was suggested earlier,
> rubygems.rb ends up requiring parsedate.rb.
>
Very odd. I noticed that earlier in the thread that you said that you
didn't have a RUBYOPTS environment variable set. The environment
variable that will get you is actually RUBYOPT. Is it possible that you
have this one set? If not then you can color me puzzled.

Oops! You can color me red. I do have RUBYOPT set and it's set to
rubygems. So that explains why the Date class is available without me
requiring it.

> This still leaves the question of why ruby-doc.org documents the Date
> class as being in the Core API.
>
Oh, that? I have no idea. :wink:

It probably shouldn't be though, eh?

Right.

···

On 2/4/06, Matthew Desmarais <desmarm@gmail.com> wrote:

> On 2/4/06, Matthew Desmarais <desmarm@gmail.com> wrote:

--
R. Mark Volkmann
Partner, Object Computing, Inc.