# How Well does Ruby support Aspect Oriented Programming?

**URL:** <https://www.ruby-forum.com/t/how-well-does-ruby-support-aspect-oriented-programming/51303>\
**Category:** Ruby\
**Created:** [December 29, 2005, 8:46am UTC](https://www.ruby-forum.com/t/how-well-does-ruby-support-aspect-oriented-programming/51303 "2005-12-29T08:46:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 29, 2005, 8:46am UTC](https://www.ruby-forum.com/t/how-well-does-ruby-support-aspect-oriented-programming/51303/1 "2005-12-29T08:46:05Z")

</div>

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.

> **[WebMD - Better information. Better health.](https://www.webmd.com/?AspectOrientedRuby)**
>
> The leading source for trustworthy and timely health and medical news and information. Providing credible health information, supportive community, and educational services by blending award-winning expertise in content, community services, expert...

> **[WebMD - Better information. Better health.](https://www.webmd.com/?AspectOrientedRuby%2FNotesRoughDrafts)**
>
> The leading source for trustworthy and timely health and medical news and information. Providing credible health information, supportive community, and educational services by blending award-winning expertise in content, community services, expert...

## 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
