为什么我会得到;未定义的方法'take';对于“数组”;在Ruby 1.8.7中?

为什么我会得到;未定义的方法'take';对于“数组”;在Ruby 1.8.7中?,ruby,ruby-1.8,Ruby,Ruby 1.8,我不确定为什么会出现这个错误,因为它在Ruby 1.8.7中似乎是一个数组 以下是相关代码: rows.each_with_index do |row, index| if (index == 0) then log "Found the following slow statements (took over #{slow_query_threshold} seconds):" end row_data = row.strip().split('|')

我不确定为什么会出现这个错误,因为它在Ruby 1.8.7中似乎是一个数组

以下是相关代码:

rows.each_with_index do |row, index|
    if (index == 0) then
        log "Found the following slow statements (took over #{slow_query_threshold} seconds):"
    end
    row_data = row.strip().split('|')
    connections = row_data[1].split(', ')
    n_more = '... and #{connections.length - 3} more' if connections.length > 3
    log %{[#{row_data[0]}] on #{connections.take(3).join(', ')} #{n_more}}
end
这给了我一个错误:

2013-04-10T05:36:45.04Z : Found the following slow statements (took over 5.0 seconds):
/myscript.rb:111: undefined method `take' for ["App15(28.39sec)"]:Array (NoMethodError)
     from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `each_with_index'

您必须在1.8.6上运行。升级,或

Ruby 1.8.7支持
take
Ruby\u版本=>“1.8.7”
%w[a b c d]。take(3)=>[“a”、“b”、“c”]
看起来Ruby版本可能早于1.8.7。因为!在我的脚本中,指向了与ruby不同的版本。