Date ::今天没有定义? [英] Date::today not defined?

查看:131
本文介绍了Date ::今天没有定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么只有一些方法的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>'

p>

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.

推荐答案

Date 观看在 lib / ruby​​gems / specification.rb中定义出于兼容性原因:

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.

如果在没有RubyGems的情况下启动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> RubyGems 2.4.0

Update

The empty Date class was removed in RubyGems 2.4.0:



  • RubyGems否longer定义了一个空的Date类。通过Benoit
    Daloze拉取请求#948

  • RubyGems no longer defines an empty Date class. Pull Request #948 by Benoit Daloze.

这篇关于Date ::今天没有定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆