Hi --
I'd like to override File.open so that it automatically searches for a
file in a list of include paths. I'm trying to use alias, but I can't
get it to work. How to I do it, please? My code to date is:
class File
alias :old_open open
def File.open(filename, *args, &block)
begin
File.old_open(filename, *args, &block)
rescue Errno::ENOENT
exception = $!
unless $options[:include_path].nil?
$options[:include_path].each do |path|
begin
return File.old_open([path, filename].join(SEPARATOR),
*args, &block)
rescue Errno::ENOENT
end
end
end
raise exception
end
end
end
I get the error:
# File.open('xxx', 'r') =>
NoMethodError: undefined method `old_open' for File:Class
from (irb):7:in `open'
from (irb):23
from (irb):3
Although a bit of re-design will avoid me having to override
File.open, I'd like to know how to do it in case it becomes
unavoidable in the future :-)
Cheers,
Tom