From: Brian Candler Date: 2007-05-24T18:52:42+09:00 Subject: Re: temporary require ,is it possible? 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 } ?