Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby runt精度错误_Ruby_Ruby On Rails 3_Gem - Fatal编程技术网

Ruby runt精度错误

Ruby runt精度错误,ruby,ruby-on-rails-3,gem,Ruby,Ruby On Rails 3,Gem,我在rails 3升级(ruby 1.9.3)中使用gem,并得到以下错误:undefined methodprecision'for nil:NilClass` 以下是如何在irb/pry上复制它: > require 'runt' => true > start_at = Runt::PDate.min(2009,1,1, 0, 0) => #<Runt::PDate: 2009-01-01T00:00:00+00:00 ((2454833j,0s,0n),+0

我在rails 3升级(ruby 1.9.3)中使用gem,并得到以下错误:
undefined method
precision'for nil:NilClass`

以下是如何在irb/pry上复制它:

> require 'runt'
=> true
> start_at = Runt::PDate.min(2009,1,1, 0, 0)
=> #<Runt::PDate: 2009-01-01T00:00:00+00:00 ((2454833j,0s,0n),+0s,2299161j)>
> end_at = Runt::PDate.min(2009,1,1, 1, 30)
=> #<Runt::PDate: 2009-01-01T01:30:00+00:00 ((2454833j,5400s,0n),+0s,2299161j)>
> runt_pattern = Runt::EveryTE.new(start_at, 600)
=> every 600 minutes starting Thu Jan  1 00:00:00 2009
> date_range = Runt::DateRange.new(start_at, end_at)
=> #<Runt::PDate: 2009-01-01T00:00:00+00:00 ((2454833j,0s,0n),+0s,2299161j)>
..
#<Runt::PDate: 2009-01-01T01:30:00+00:00 ((2454833j,5400s,0n),+0s,2299161j)>
> schedule = Runt::Schedule.new
=> #<Runt::Schedule:0x007fd46cad56b8 @elems={}>
> schedule.add 'events', runt_pattern
=> every 600 minutes starting Thu Jan  1 00:00:00 2009
> schedule.dates('events', date_range)
NoMethodError: undefined method `precision' for nil:NilClass
from /Users/ttt/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/runt-0.7.0/lib/runt/dprecision.rb:121:in `<=>'
>需要“runt”
=>正确
>start_at=Runt::PDate.min(2009,1,1,0,0)
=> #
>end_at=Runt::PDate.min(2009,1,1,30)
=> #
>矮子模式=矮子::EveryTE.new(从600开始)
=>自2009年1月1日星期四起每600分钟一次
>date\u range=Runt::DateRange.new(开始于,结束于)
=> #
..
#
>schedule=Runt::schedule.new
=> #
>schedule.add“events”,runt\u模式
=>自2009年1月1日星期四起每600分钟一次
>计划日期(“事件”,日期范围)
NoMethodError:nil类的未定义方法“精度”
from/Users/ttt/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/runt-0.7.0/lib/runt/dprecision.rb:121:in`'
有人知道这件事吗

这似乎是由以下行触发的:,但仍在试图找出如何进一步挖掘代码

我注意到有一些更新的runt版本,例如,但是它们似乎也不能解决这个问题

它在ree-1.8.7-2011.03上的rails2上工作,并返回
[Thu,01 Jan 2009 00:00:00+0000]


编辑:添加rails2返回的内容。

您的问题似乎出在。在initialize方法中,有一个可选的精度参数

class EveryTE

  include TExpr

  def initialize(start,n,precision=nil)
    @start=start
    @interval=n
    # Use the precision of the start date by default
    @precision=precision || @start.date_precision
  end

  def include?(date)
    i=DPrecision.to_p(@start,@precision)
    d=DPrecision.to_p(date,@precision)
    while i<=d
      return true if i.eql?(d)
      i=i+@interval
    end
    false
  end

  def to_s
    "every #{@interval} #{@precision.label.downcase}s starting #{Runt.format_date(@start)}"
  end

end
以下是精度的完整列表(单位为):


因为它可以在rails 2上工作,并且可能使用activesupport。因此,我认为存在与rails 3的activesupport不兼容的情况。因为你发送的代码已经有4年历史了。有没有一个地方可以显示发生了什么变化?我想这可能更像是ruby 1.8.7到ruby 1.9.3的问题,因为我在这个库中找到了另一个问题。它适用于ruby 1.9.2p290-一定是什么改变了到ruby 1.9.3我尝试了这个,并得到了相同的错误。另外,
@precision
将等于此行:
start_at.precision
(DPrecision::MINUTE),因此在这种情况下它不会为零。此外,作为参考,并在控制台中测试它,您将使用
runt_模式=runt::EveryTE.new(start_at,600,runt::DPrecision::precision.min)
> runt_pattern = Runt::EveryTE.new(start_at, 600,Runt::DPrecision::Precision.sec)
Precision.year
Precision.month
Precision.week
Precision.day
Precision.hour
Precision.min
Precision.sec
Precision.millisec