How Well does Ruby support Aspect Oriented Programming?


#1

Here’s my question, I would really appreciate input from the list.

What is the most basic, narrowest AOP feature that Ruby can not support
without language extensions?

Take “support” to be a very broad term. If Ruby can effectively
provide the same functionality, but perhaps with a different syntax or
with a reasonable number of “hoops,” that’s fine.

For reference, here are 2 wiki pages that prompted this question. My
contention, based on my very limited knowledge of Ruby and AOP, is that
some/many of the language extensions proposed here are not necessary,
but I would be happy to be proven wrong. I really just want input from
the group.

http://www.rubygarden.org/ruby?AspectOrientedRuby
http://www.rubygarden.org/ruby?AspectOrientedRuby/NotesRoughDrafts

What follows is the thought process that drove me to ask this question
of the group

From the first link, here is a code example involving a “cut,” a
proposed language extension


cut A < C
def m1
print ‘{’, super, ‘}’
end
end

C.new.m1 #=> {1}


I believe anything accomplished here can just as easily be accomplished
by aliasing the existing m1 method, and (re)def’ing C#m1, calling the
old method (via the alias) from the new. Obviously, taking my example
literally, that’s far too much work for a common construct. The
systemized, native ruby version of that would look something as
follows, with wrap method being a method on Object utilizing the eval
methods (i.e. metaprogramming). I have a working implementation of
both of these methods.

class C
wrap_method (m1), { |this,old_method,*args| “(” +
old_method(*args).to_s + “)” }
end

A similar method takes 2 blocks, with the first determining what
methods to wrap

class C
wrap_matching_methods { |method| method == “m1” } {
|this,old_method,*args| “(” + old_method(*args).to_s + “)” }
end

Clearly, the code from the article I quoted is merely a simple example,
and does not encompass all functionality. I use it as a cherry-picked
example.

I look forward to everyone’s input

Thanks,
Mike