built-in vs. standard library

Discussion in 'Ruby' started by Mark Volkmann, Feb 4, 2006.

  1. 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.
     
    Mark Volkmann, Feb 4, 2006
    #1
    1. Advertising

  2. 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
     
    James Edward Gray II, Feb 4, 2006
    #2
    1. Advertising

  3. On 2/4/06, James Edward Gray II <> 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>
     
    Wilson Bilkovich, Feb 4, 2006
    #3
  4. On 2/4/06, James Edward Gray II <> 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.
     
    Mark Volkmann, Feb 4, 2006
    #4
  5. Mark Volkmann

    Ross Bamford Guest

    On Sat, 04 Feb 2006 23:23:36 -0000, Mark Volkmann
    <> wrote:

    > On 2/4/06, James Edward Gray II <> 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 -
     
    Ross Bamford, Feb 5, 2006
    #5
  6. Mark Volkmann wrote:
    > On 2/4/06, James Edward Gray II <> 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.
     
    Matthew Desmarais, Feb 5, 2006
    #6
  7. On 2/4/06, Ross Bamford <> wrote:
    > On Sat, 04 Feb 2006 23:23:36 -0000, Mark Volkmann
    > <> wrote:
    >
    > > On 2/4/06, James Edward Gray II <> 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.
     
    Mark Volkmann, Feb 5, 2006
    #7
  8. On 2/4/06, Matthew Desmarais <> 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.
     
    Mark Volkmann, Feb 5, 2006
    #8
  9. Mark Volkmann wrote:
    > On 2/4/06, Matthew Desmarais <> 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?
     
    Matthew Desmarais, Feb 5, 2006
    #9
  10. On 2/4/06, Matthew Desmarais <> wrote:
    > Mark Volkmann wrote:
    > > On 2/4/06, Matthew Desmarais <> 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.
     
    Mark Volkmann, Feb 5, 2006
    #10
  11. Mark Volkmann

    James Britt Guest

    Mark Volkmann wrote:
    > On 2/4/06, Matthew Desmarais <> 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
     
    James Britt, Feb 5, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fredrik Lundh
    Replies:
    0
    Views:
    434
    Fredrik Lundh
    Feb 4, 2005
  2. Daniel Bickett
    Replies:
    0
    Views:
    383
    Daniel Bickett
    Feb 4, 2005
  3. steve.leach

    How standard is the standard library?

    steve.leach, Apr 18, 2005, in forum: Python
    Replies:
    1
    Views:
    395
    Christos TZOTZIOY Georgiou
    Apr 18, 2005
  4. funkyj
    Replies:
    5
    Views:
    1,134
    funkyj
    Jan 20, 2006
  5. Carmen Sei
    Replies:
    4
    Views:
    847
    James Kanze
    Mar 5, 2008
Loading...

Share This Page