From: Ed Howland Date: 2005-10-27T08:24:33+09:00 Subject: Re: [ANN] [RCR] Cut-based AOP On 10/18/05, Trans wrote: > This is to "officially" announce an RCR that I posted to RCR archive > two days ago. I realize the RCR itself is a bit dense and techincial, > so (with thanks to ES) I thought it might be a good idea to provide a > little summary and some examples of what it's all about and why it's a > such a good approach to AOP for Ruby. > The concept seems clear to me. But I have an aditional question. Will cuts be allowed on root classes that are themselves extruded from a 'C' extension? E.g. I don't really know if class IO is mostly C extension stuff, but could a cut be applied to these class types? Kernel? Object? cut AspectIO < IO def puts(*args) # do something with the args super end end If I am understanding the syntax correctly. I don't know how the internal hooking mechanism works here. But even if IO#puts is a low-level C funtion, then super could just map to it, instead of the normal ruby implementation of the method. If so, then this could be a very powerful mechanism in Unit Testing: (Again, forgive me if the syntax is wrong, here.) class IOTest < Test::Unit::TestCase @output = '' cut AspectIO < IO def puts(*args) @output = args.to_s super end end def setup @oldio = $stdio $stdio = IO.new end def test_hello puts "Hello world" # having the advantage of making @output avail to assertions # and spewing contents in the console. assert_equals "Hello world", @output end def teardown $stdio = @oldio end end Is this acceptable in the RCR design? Was it already implied? Thanks Ed