09.12.07

NoMethodError: undefined method `copy’ for File:Class

Posted in Ruby at 9:00 am by Željko Filipin

I wanted to copy a file from Ruby. Documentation for File#copy
said that

should work. But, I got this error message:

NoMethodError: undefined method `copy' for File:Class

Google search led me to ruby-talk post that said I should do:

I am just surprised that documentation did not make that clear.

5 Comments »

  1. bret said,

    September 21, 2007 at 8:53 pm

    Actually that documentation does make that pretty clear. I think you just missed it. Take another look at the top of that file.

  2. Željko Filipin said,

    September 24, 2007 at 10:31 am

    Thanks Bret, I have noticed that they mention ftools, but I thought I was using only File class, not ftools. I really did not understand that I should require ftools if I wanted to use File#copy. I have read it now several times, and I still think it is not explicit enough.

    Well, maybe it is just me, or me not being native speaker.

  3. Ajay said,

    October 10, 2007 at 2:50 pm

    I agree that the docs are confusing as they say ftools and FileUtils (which one are we supposed to use) add methods to the File class but why would we use them when the docs for the base File class show a built-in copy command? Unfortunately, there is no built-in copy command in the source for the base File class so the docs are WRONG.

  4. Dave Conrad said,

    October 9, 2008 at 11:14 pm

    Hey Željko, it’s over a year later and your blog post just saved my sanity. I had a small test script that I had put “require ‘ftools’” at the top of, but I forgot it from the main script I was working on.

    I was going crazy trying to figure out why it worked in my simple test, but didn’t work in the context of the larger script I was writing. Thank you!

  5. Željko Filipin said,

    October 10, 2008 at 9:14 am

    Dave, I am glad I could help you. :)

Leave a Comment