Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > built-in vs. standard library

Reply
Thread Tools

built-in vs. standard library

 
 
Mark Volkmann
Guest
Posts: n/a
 
      02-04-2006
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. Tr=
ue?

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


 
Reply With Quote
 
 
 
 
James Edward Gray II
Guest
Posts: n/a
 
      02-04-2006
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.

James Edward Gray II


 
Reply With Quote
 
 
 
 
Wilson Bilkovich
Guest
Posts: n/a
 
      02-04-2006
On 2/4/06, James Edward Gray II <(E-Mail Removed)> 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.
>


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

irb(main):001:0> Date.methods(false)
=3D> ["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'
=3D> true
irb(main):004:0> Date.today
=3D> #<Date: 4907541/2,0,2299161>
irb(main):005:0> Date.methods(false)
=3D> ["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>


 
Reply With Quote
 
Mark Volkmann
Guest
Posts: n/a
 
      02-04-2006
On 2/4/06, James Edward Gray II <(E-Mail Removed)> 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.


Then why does this code run?

d =3D 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.


 
Reply With Quote
 
Ross Bamford
Guest
Posts: n/a
 
      02-05-2006
On Sat, 04 Feb 2006 23:23:36 -0000, Mark Volkmann
<(E-Mail Removed)> wrote:

> On 2/4/06, James Edward Gray II <(E-Mail Removed)> 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.

>
> 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 just get 3 (which I think is expected). Do you require rubygems in your
..irbrc? or $RUBYOPTS?

--
Ross Bamford - http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Matthew Desmarais
Guest
Posts: n/a
 
      02-05-2006
Mark Volkmann wrote:
> On 2/4/06, James Edward Gray II <(E-Mail Removed)> 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.
>>

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


 
Reply With Quote
 
Mark Volkmann
Guest
Posts: n/a
 
      02-05-2006
On 2/4/06, Ross Bamford <(E-Mail Removed)> wrote:
> On Sat, 04 Feb 2006 23:23:36 -0000, Mark Volkmann
> <(E-Mail Removed)> wrote:
>
> > On 2/4/06, James Edward Gray II <(E-Mail Removed)> 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.

> >
> > Then why does this code run?
> >
> > d =3D 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.

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


 
Reply With Quote
 
Mark Volkmann
Guest
Posts: n/a
 
      02-05-2006
On 2/4/06, Matthew Desmarais <(E-Mail Removed)> 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.

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


 
Reply With Quote
 
Matthew Desmarais
Guest
Posts: n/a
 
      02-05-2006
Mark Volkmann wrote:
> On 2/4/06, Matthew Desmarais <(E-Mail Removed)> 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.

It probably shouldn't be though, eh?



 
Reply With Quote
 
Mark Volkmann
Guest
Posts: n/a
 
      02-05-2006
On 2/4/06, Matthew Desmarais <(E-Mail Removed)> wrote:
> Mark Volkmann wrote:
> > On 2/4/06, Matthew Desmarais <(E-Mail Removed)> 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 t=

he
> >> 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.
>
> It probably shouldn't be though, eh?


Right.

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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rum-Time Library vs Standard Library Carmen Sei C++ 4 03-05-2008 10:09 AM
add pexpect to the standard library, standard "install" mechanism. funkyj Python 5 01-20-2006 08:35 PM
How standard is the standard library? steve.leach Python 1 04-18-2005 04:07 PM
Re: Possible additions to the standard library? (WAS: Aboutstandard library improvement) Daniel Bickett Python 0 02-04-2005 11:22 AM
Re: Possible additions to the standard library? (WAS: Aboutstandard library improvement) Fredrik Lundh Python 0 02-04-2005 07:34 AM



Advertisments