以未定义的方法`visit_Array'升级结果

时间:2014-11-27 20:06:54

标签: ruby activerecord yaml

我正在尝试将系统上的Ruby版本从1.8升级到1.9或2.0。

但是我写了一个程序,我也想升级,但是我遇到了问题 我无法弄清楚如何解决。

使用Active Record 2.3.18在Ruby 1.8下运行良好,但现在我已安装 Ruby 2.0.0和Active Record 4.0.11。

但它现在抱怨在Psych框架中有一个未定义的方法'visit_Array'。

这是我程序的堆栈跟踪:

>> ~/stocks $ ruby20 StockFind.rb IBM
/usr/lib/ruby/2.0.0/psych/visitors/visitor.rb:15:in `visit': undefined method `visit_Array' for #<Psych::Visitors::ToRuby:0x88c0d90> (NoMethodError)
from /usr/lib/ruby/2.0.0/psych/visitors/visitor.rb:5:in `accept'
from /usr/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:20:in `accept'
from /usr/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:267:in `block in revive_hash'
from /home/shs/stocks/Stock.rb:26:in `each_slice'
from /usr/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:266:in `revive_hash'
from /usr/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:141:in `visit_Psych_Nodes_Mapping'
from /usr/lib/ruby/2.0.0/psych/visitors/visitor.rb:15:in `visit'
from /usr/lib/ruby/2.0.0/psych/visitors/visitor.rb:5:in `accept'
from /usr/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:20:in `accept'
from /usr/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:240:in `visit_Psych_Nodes_Document'
from /usr/lib/ruby/2.0.0/psych/visitors/visitor.rb:15:in `visit'
from /usr/lib/ruby/2.0.0/psych/visitors/visitor.rb:5:in `accept'
from /usr/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:20:in `accept'
from /usr/lib/ruby/2.0.0/psych/nodes/node.rb:35:in `to_ruby'
from /usr/lib/ruby/2.0.0/psych.rb:130:in `load'
from /home/shs/stocks/StockStore.rb:6:in `<top (required)>'
from /usr/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in `require'
from /usr/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in `require'
from StockFind.rb:1:in `<main>'

each_slice函数的定义如下:

class Array
  def each_slice(slice_length)
    last=slice_length-1
    i=0
    while (i+last)<self.length do
      yield(self[i..i+last],i,i+last)
      i+=1
    end
    i
  end
end

1 个答案:

答案 0 :(得分:2)

您应该在代码中重命名方法each_slice,因为此方法是自1.8.6以来Enumerable API的一部分。 psych gem使用它,并期望有不同的行为。