Ruby/Development/Aspect Oriented Programming
Материал из Wiki.crossplatform.ru
Версия от 17:10, 26 мая 2010; (Обсуждение)
Doing Aspect-Oriented Programming
require "aspectr" class Verbose < AspectR::Aspect def describe(method_sym, object, *args) "#{object.inspect}.#{method_sym}(#{args.join(",")})" end def before(method_sym, object, return_value, *args) puts "About to call #{describe(method_sym, object, *args)}." end def after(method_sym, object, return_value, *args) puts "#{describe(method_sym, object, *args)} has returned " + return_value.inspect + "." end end verbose = Verbose.new stack = [] verbose.wrap(stack, :before, :after, :push, :pop) p stack.push(10) p stack.pop