Brian Candler
5/24/2007 9:53:00 AM
On Thu, May 24, 2007 at 06:03:22PM +0900, Gpy Good wrote:
> I have a idea,it is "temporary require"
> [code]
> module Find
> # my define
> end
>
> tmp_require("find"){
> #do something with "Find.find" method,temporary!!
> }
>
> puts Find # my define,no "Find.find" method
> [/code]
> Is it possible?
Hmm, I was thinking of
temp = load("find.rb", true)
temp::Find.find(...)
but unfortunately load returns true, not the module object :-(
Here's a messy way:
require 'find' # the _old_ implementation of find
#require 'new_find' # contains the following:
module NewStuff
module Find
def self.find
puts "hello"
end
end
end
# Main program
old_find = Find rescue nil
begin
Find = NewStuff::Find
Find.find # this is the code to be executed
ensure
Find = old_find
end
Find.find(".") { |f| puts f }
?