Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `copy' for File:Class

Tags:

ruby-1.9.2

I've just upgraded a project to Ruby 1.9.2 and the following line crashes the app with 'undefined method `copy' for File:Class'

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

I have the following libraries loaded in this module

require 'zip/zipfilesystem'
require 'iconv'
require 'net/ftp'
require 'fileutils'
like image 228
creativetechnologist Avatar asked Aug 03 '11 10:08

creativetechnologist


2 Answers

It should actually be FileUtils.copy or FileUtils.cp. I wonder how your old project worked with just File.copy, as File doesn't have that method.

refer here: http://santoro.tk/mirror/ruby-core/classes/FileUtils.html#M004325

like image 189
corroded Avatar answered Oct 12 '22 01:10

corroded


You were probably using ftools in 1.8:

ftools adds several (class, not instance) methods to the File class, for copying, moving, deleting, installing, and comparing files, as well as creating a directory path. See the File class for details.

ftools was replaced by fileutils in 1.9, about the 6th element in this list of standard library changes in 1.9 from Dave Thomas

like image 20
klochner Avatar answered Oct 12 '22 02:10

klochner