If I try a modification to custom_require and just run the code (in
netbeans) the paths are not listed, whereas if debugging, the paths are
listed.
a) What is the program flow in jruby that causes this?
b) IF it is possible to override (monkey patch) custom require, how
would it need to be done? I have tried monkey patching the kernel but
my attempt did not work.
def require(path) # :doc:
puts path # <<<< trivial addition
gem_original_require path
rescue LoadError => load_error
if load_error.message =~ /#{Regexp.escape path}\z/ and
spec = Gem.searcher.find(path) then
Gem.activate(spec.name, “= #{spec.version}”)
gem_original_require path
else
raise load_error
end
end
If I try a modification to custom_require and just run the code (in
netbeans) the paths are not listed, whereas if debugging, the paths
are listed.
This seems to be related to requiring rubygems. It seems the debugger
requires rubygems automatically, whereas my code had not required
rubygems.
On Tue, Nov 24, 2009 at 10:18 PM, Paul F Fraser [email protected]
wrote:
b) IF it is possible to override (monkey patch) custom require, how would
it need to be done? I have tried monkey patching the kernel but my attempt
did not work.
I had to do this once in order to run functional tests against
rubygems itself. Here’s how:
# point "require" back at the standard Ruby "require" method
# if RubyGems has already aliased gem_original_require to the
original require…
if Kernel.private_method_defined?(:gem_original_require)
# get an unbound method reference to the original require method
unbound_gem_original_require = Kernel.send(:instance_method,
:gem_original_require)
# then remove the overridden RubyGems require
Kernel.send(:remove_method, :require)
# and define require to invoke the original require method
Kernel.send(:define_method, :require) {|path|
unbound_gem_original_require.bind(Kernel).call(path) }
end