From: Sean O'Halpin Date: 2007-11-03T08:43:04+09:00 Subject: Re: Who required that!? On 11/2/07, Joel VanderWerf wrote: > Sean O'Halpin wrote: > > > Using alias is just a little too fragile. You could always generate a > > unique alias name (using GUID or something) which would avoid the > > problem, but grabbing a reference to the existing method and using > > that is sure to work. > > Can you do the latter without breaking gem's require? > > -- > vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407 > > Yes, that's the point. If you redefine require by chaining to the previous definition (rather than aliasing) no other part of the system will know the difference. But the proof is in the pudding :) require 'rubygems' BEGIN { module Kernel h = Hash.new define_method(:requiree) do |of| h[of] end r = method :require define_method(:require) do |*a| r.call *a h[a.first] = caller end end } require 'main' p Kernel.requiree("main") Main { def run puts "Made it!" end } __END__ $ ruby requiree.rb ["/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `gem_original_require'", "/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `require'", "requiree.rb:19"] Made it! Regards, Sean