【问题标题】:undefined method `copy' for File:Class文件:类的未定义方法“复制”
【发布时间】:2011-10-18 23:30:07
【问题描述】:

我刚刚将一个项目升级到 Ruby 1.9.2,以下行使用 'undefined method `copy' for File:Class' 使应用程序崩溃

File.copy(animage.image.path(:export), destfile)

我在这个模块中加载了以下库

require 'zip/zipfilesystem'
require 'iconv'
require 'net/ftp'
require 'fileutils'

【问题讨论】:

  • 不应该是File.cp吗?或者更确切地说是 FileUtils.cp

标签: ruby-1.9.2


【解决方案1】:

实际上应该是FileUtils.copyFileUtils.cp。我想知道您的旧项目如何仅使用 File.copy,因为 File 没有该方法。

参考这里:http://santoro.tk/mirror/ruby-core/classes/FileUtils.html#M004325

【讨论】:

    【解决方案2】:

    您可能在 1.8 中使用 ftools

    ftools 向 File 类添加了几个(类,而不是实例)方法,用于复制、移动、删除、安装和比较文件,以及创建目录路径。有关详细信息,请参阅 File 类。

    ftools 在 1.9 中被 fileutils 取代,大约是 Dave Thomas 的 list of standard library changes in 1.9 中的第 6 个元素

    【讨论】:

      猜你喜欢
      • 2014-08-31
      • 1970-01-01
      • 2015-02-12
      • 2017-02-14
      • 1970-01-01
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 2022-12-23
      相关资源
      最近更新 更多