为什么我不能使用Ruby获得明天的约会?

时间:2013-08-05 17:51:16

标签: ruby

为什么我不能使用Ruby获得明天的约会?以下是一些经常失败的事情:

Time.now.tomorrow
Date.tomorrow
Date.current.tomorrow
Date.current+1

我无法弄清楚出了什么问题。我在Windows上使用Ruby 1.8.7,这可能是问题所在。

感谢任何帮助。

3 个答案:

答案 0 :(得分:3)

这些都是rails(特定的Active Support)添加的东西。如果你正在编写一个非Rails项目,那么你将无法使用它们而不需要适当的Active Support。

例如:

require 'active_support/core_ext/date'
require 'active_support/core_ext/time'

应引入添加到DateTime的大部分功能。

答案 1 :(得分:1)

只需使用the succ method within 'date'

require 'date'
d = Date.new(2013,8,5)
d = d.succ

在REPL中,d.to_s生成"2013-08-06"的输出。

答案 2 :(得分:1)

请参阅Active Support的“Extensions to Time”。

整个页面都是关于如何挑选你需要的扩展,而不是整个Active Support库。

出于您的目的,您可能需要:

require 'active_support/core_ext/time/calculations'

如果您没有核心扩展,那么您应该升级您的Rails,但这可能会破坏您可能拥有的任何旧Rails应用程序。如果你在Ruby 1.8.7上运行,那么你很可能已经过时了。此时,您应该了解如何使用RVM或rbenv来管理沙箱中的Ruby安装或Windows等效项。