From: Gavin Sinclair Date: 2003-11-22T15:19:33+09:00 Subject: Method wrapper question (was "stereotyping (was ...)) On Saturday, November 22, 2003, 10:53:39 AM, Yukihiro wrote: [On how one might 'implement' interfaces:] > I prefer Jim Weirich's idea in [ruby-talk:86007], utilizing method > combination. > in the library code foo.rb: > require 'foo_if' > # which defines interface > # you can comment out from production code > class Foo > def greet(hi) > hi.display > print "\n" > end > end > in the foo_if.rb: > class Foo > def greet:pre(hi) > assert hi.respond_to? :display > end > end > with probably interface checking cosmetic. I'm not buying into the interface debate one way or the other, but a related question here is: how do you envisage :pre, :post, etc., working if they are defined multiple times? This is important because they could be used to implement some aspect-oriented code, and then also be used to implement some interface checking. For example: class Example def meth(o) # some code on 'o' end def meth:pre(o) logger.info "About to process #{o}" end def meth:pre(o) assert o.responds_to? :display end end Do both the :pre method wrappers get executed? If so, in what order? If not, which one does? And why not execute both? Gavin