0

在 Rails(但不是普通的 Ruby)中,可以这样说:

t = 2.days
t.inspect 

=>“2天”

t.to_i

=> 172800

它看起来像 Rails 修补了 Fixnum,因此它隐藏了由间隔表示的秒数和带有描述的检查字符串。这基本上是如何工作的?

4

1 回答 1

2

ActiveSupport 对基本 Ruby 类(如字符串、对象和数字)进行了核心扩展,使之成为可能。

更多关于 Rails 指南:http ://edgeguides.rubyonrails.org/active_support_core_extensions.html#time

ActiveSupport 正在将“天”添加到数字中,并进行计算以提供给您

代码:https ://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/numeric/time.rb

这是非常基本的:

  • 1 天是 24 小时
  • 1小时是60分钟
于 2013-06-21T03:11:14.593 回答