On Wednesday, January 29, 2003, 4:22:14 AM, Tom wrote:

> 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:

Guy has answer, I'll expand in case you didn't fully get it, and then
offer an advicelet.

  class File
    class << File
      alias old_open open
    end
  end

OR

  class File
    class << self
      alias old_open open
    end
  end


If I were you, I wouldn't be redefining such an important method, at
least not without damn good reason.  I see no reason not to simply add
your own:

  class << File
    def find_and_open(name, *args, &block)    # Want a better name.
      path = find_file(name)
      File.open(path, *args, &block)
    end

    def find_file(name)
      # ...
    end
    private :find_file
  end

  
The resulting code looks more elegant anyway, since there is a
separation of concerns.

Gavin