From: hipster Date: 2001-07-23T21:24:13+09:00 Subject: [ruby-talk:18340] Re: Ruby, Python and Objects philosophy On Mon, 23 Jul 2001 21:03:34 +0900, Lloyd Zusman wrote: > > And now, I have a question: could you show us how the example above would > be coded in Ruby? Your pseudo-code is very nice, but a good, concrete, > totally runnable Ruby example of the exact logging scenario that you have > spoken about would be even better. Logging example using Aspect Oriented Programming (get aspectr from the RAA): require "aspectr" include AspectR class Logger < Aspect def wrap(target, *methods) super(target, :enter, :exit, *methods) end def enter(method, object, *args) puts "enter #{object.class}::#{method}" end def exit(method, object, *args) puts "exit #{object.class}::#{method}" end end class SomeTargetClass def method_a puts "method_a" end end logger = Logger.new # wrap one method on the class. One can also wrap a list of methods, both # on classes and instances. logger.wrap(SomeTargetClass, :method_a) SomeTargetClass.new.method_a # -> # enter SomeTargetClass::method_a # method_a # exit SomeTargetClass::method_a Analogue solutions for timers, synchronisation, design patterns, & c. Warning: AOP is contagious :) HTH, Michel