From: "trans (Thomas Sawyer)" Date: 2012-12-17T01:28:08+09:00 Subject: [ruby-core:50921] [ruby-trunk - Feature #7548] Load and Require Callbacks Issue #7548 has been updated by trans (Thomas Sawyer). =begin Some additional thoughts on this. It occurs to me that #prepend would make this a ((*little*)) easier now. One could do: module LoadCallbacks def load(*args) super(*args) $stderr.puts "load: %s" % [args.inspect] end def require(*args) super(*args) $stderr.puts "require: %s" % [args.inspect] end def require_relative(*args) super(*args) $stderr.puts "require: %s" % [args.inspect] end end module Kernel prepend LoadCallbacks class << self prepend LoadCallbacks end end That's a little more elegant, but still feels a bit clunky. I think what would really make the difference, and what would make this callback feature request effectively pointless, is if Ruby had a single method through which all loading was routed. So (({#load})), (({#require})) and (({#require_relative})) would all call this one method passing in options (i.e. named parameters) to tell it which kind of loading is to happen. That would be nice b/c it would allow us a single target method to see what was going on, instead of the current ((*six*)) methods! =end ---------------------------------------- Feature #7548: Load and Require Callbacks https://bugs.ruby-lang.org/issues/7548#change-34778 Author: trans (Thomas Sawyer) Status: Open Priority: Normal Assignee: Category: Target version: next minor =begin Should #load and #require have callbacks? e.g. def required(path) ... end def loaded(path, wrap) ... end On occasion I have wanted to do load monitoring to track down a bug. This would have made it easier. Are there any other good use cases? =end -- http://bugs.ruby-lang.org/