我遇到过以下代码:
class MethodLogger def log_method((klass,method_name) klass.class_eval do alias_method "#{method_name}_original" method_name define_method method_name do puts "#{Time.Now}: Called #{method_name}" send "#{method_name}_original" end end end end class Tweet def say_hi puts "Hi" end end logger =MethodLogger.new logger.log_method(Tweet,:say_hi)
这给出了输出
2012-09-11 12:54:09 -400: Called say_hi
那么,define_method:say_hi如何覆盖原始方法:say_hi?或者define_method是否更改了原始方法定义?