日期::今天没有定义? [英] Date::today not defined?
问题描述
为什么只有一些Date类的方法没有显式加载:
Why are only some methods of the Date class loaded without an explicit:
require 'date'
行?
例如:
irb(main):002:0> Date.today
NoMethodError: undefined method `today' for Date:Class
from (irb):2
from /Users/mwlang/.rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in `<main>'
然后...
And then...
irb(main):003:0> require 'date'
=> true
导致...
irb(main):004:0> Date.today
=> #<Date: 2013-04-12 ((2456395j,0s,0n),+0s,2299161j)>
http://ruby-doc.org/stdlib-2.0/libdoc/date/rdoc/Date.html 似乎没有提供明确的解释。评论#irc说它的一个stdlib而不是核心库,但核心甚至没有Date类定义和启动irc与-f(抑制阅读.irbrc),以获得最小的负载仍然似乎加载某种基/核心日期类。
The documentation at http://ruby-doc.org/stdlib-2.0/libdoc/date/rdoc/Date.html seems to offer no explicit explanation for this behavior. Comments on #irc say its a stdlib rather than core library, but core doesn't even have Date class defined and launching irc with -f (suppress reading .irbrc) to get a minimal load still appears to load some sort of base/core Date class.
想要解释这个问题的技术说明,并引用了Ruby文档,这样我就可以从Ruby 1.8中切换出来,了解其他遇到的问题。 7到Ruby 2.0.0。
Would like a technical explanation of what's going on and references to the Ruby docs that explain this so I understand for other such encounters as I switch from Ruby 1.8.7 to Ruby 2.0.0.
推荐答案
日期
查看在 lib / rubygems / specification中定义。 rb 兼容性原因:
# 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.
如果在没有RubyGem的情况下启动IRB,那么Date类就会消失:
If starting IRB without RubyGems, that Date class is gone:
$ ruby --disable-gems -S irb
irb(main):001:0> Date
NameError: uninitialized constant Date
更新
在日期类。 txt#L45rel =nofollow noreferrer> RubyGems 2.4.0 :
Update
The empty Date
class was removed in RubyGems 2.4.0:
- RubyGems不再定义一个空的Date类。请求#948 由Benoit
Daloze。
- RubyGems no longer defines an empty Date class. Pull Request #948 by Benoit Daloze.
这篇关于日期::今天没有定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!