From: Yusuke ENDOH Date: 2009-09-01T04:22:24+09:00 Subject: [ruby-core:25234] Re: Module#prepend and Array#prepend 2009/9/1 Yukihiro Matsumoto : > Hi, > > In message "Re: [ruby-core:25228] Re: Module#prepend and Array#prepend" > on Tue, 1 Sep 2009 03:24:30 +0900, Yusuke ENDOH writes: > > |However, I think that module inclusion is not such a patching tool; > |open class is. > > |Then, I guess that what we really need is a method wrapping feature: > | > | class Person > | refine_method(:speak) do |old_method, words| > | # old_method is a Method of original definition > | old_method.call("#{ words }!") > | end > | end > | Person.new.speak("matz") #=> "matz!" > > Can you elaborate why you think module inclusion is not such a > patching tool, I have understood that module mix-in is just adding a concern because, as far as I know, the built-in modules (i.e., Comparable, Enumerable, etc.) merely add methods and do not modify existing methods of original class. > and the above "refine_method" is sought solution than > Module#prepend? I thought: - we should use open class or reflection to redefine an existing method, - but it is burdensome to redefine a method with using its original behavior, - then, the method to do it may be helpful. -- Yusuke ENDOH