warning: toplevel constant File referenced by IO::File
I want to delete a file from Application::Mail.download. The problem is that inside Application module, File.delete calls Application::File.delete.
module Application
class File
def delete
end
end
class Mail
def self.download
File.delete “mail.eml”
end
end
end
Application::Mail.download
Run this code and you will get error message:
Exception: undefined method `delete' for Application::File:Class
I could rename Application::File to something else, but I created Application module because I wanted to name my classes as I wish without conflicts with Ruby classes.
One solution is to specify that I want to call IO::File.delete.
def self.download
IO::File.delete “mail.eml”
end
But then I get this warning:
warning: toplevel constant File referenced by IO::File
How to ignore warning thread at ruby-forum.com provided the solution to removing warning. Add this at the beginning of the file:
$VERBOSE = nil
But, I want to see other warnings. I know I can change the value of $VERBOSE to nil just before I call IO::File.delete and then change it back. That just feels wrong. Why am I getting that warning after all? Why do I get the warning after calling IO::File.delete? Am I doing something wrong?
I posted this also to Watir General Google group and Charley Baker replied that I will not get the warning message if I use ::File.delete instead of IO::File.delete.
Željko Filipin
26 Oct 07 at 10:42 am