Date::today not defined?

后端 未结 2 953
萌比男神i
萌比男神i 2020-12-31 11:27

Why are only some methods of the Date class loaded without an explicit:

require \'date\'

line?

For example:

irb(mai         


        
相关标签:
2条回答
  • 2020-12-31 11:39

    The Date class you are seeing is defined in lib/rubygems/specification.rb for compatibility reasons:

    # date.rb can't be loaded for `make install` due to miniruby
    # Date is needed for old gems that stored #date as Date instead of Time.
    class Date; end
    

    It's an empty class definition and it doesn't provide any methods or functionality.

    If starting IRB without RubyGems, that Date class is gone:

    $ ruby --disable-gems -S irb
    irb(main):001:0> Date
    NameError: uninitialized constant Date
    

    Update

    The empty Date class was removed in RubyGems 2.4.0:

    • RubyGems no longer defines an empty Date class. Pull Request #948 by Benoit Daloze.
    0 讨论(0)
  • 2020-12-31 11:42

    Complementing @Stefan answer:

    Please note that This has been removed, in later version of rubygems.

    • Changelog here
    • Merge Request here
    0 讨论(0)
提交回复
热议问题