Generally, if you want to patch some built-in method, you should first make an alias for the original method. Most of the time you'll call the old one somewhere in your overriding method. Otherwise you'll lost the functionality of the original method and it's likely to break the application logic.
- Use
ri require
or read the documentation to find out where the require
method is defined. You'll find it's in Kernel
module. Besides, you'll find its method signature so you know what the parameter list looks like.
- Monkey patch module
Kernel
. DON'T break the functionality unless you know what you are doing.
module Kernel
# make an alias of the original require
alias_method :original_require, :require
# rewrite require
def require name
puts name
original_require name
end
end
# test the new require
require 'date'