AOP in Ruby


#1

Hi there,

I was wondering if there is any support (in the form of frameworks or
whatever) for AOP in Ruby?

Ciao,
Mark.


#2

Mark Collins-Cope wrote:

Hi there,

I was wondering if there is any support (in the form of frameworks or
whatever) for AOP in Ruby?

There seems to be some:
http://raa.ruby-lang.org/search.rhtml?search=aop

robert

#3

I thought aspects were baked into the language. You just have to
re-open a
definition like:

class A
def a_method
# do something
end
end

class B < A
alias old_a_method a_method

def a_method
puts “I’m an aspect”

old_a_method

end
end

Maybe I’m climbing up the wrong tree. Dependency injection and AOP are
different problems aren’t they?

‘There was an owl lived in an oak.
The more he heard, the less he spoke.
The less he spoke, the more he heard.’

Christian L.
removed_email_address@domain.invalid


#4

Ed Howland wrote:

I’ve tried this out and it seems to work fairly well in my limited

Mark.
I think I prefer the Sydney approach to AOP, which uses Behaviors:

http://hoshi.fallingsnow.net/svn/sydney/trunk/lib/behavior/aop.rb

Regards,

Dan


#5

I like the Sydney stuff a little more too… Seems cleaner somehow.

The RCR sounded neat up until I got to: “A way to specify alternate
method-to-advice mappings” where it started to break down for me. An
interesting read though.

Chris


#6

On 11/28/05, Daniel B. removed_email_address@domain.invalid wrote:

Ed Howland wrote:

I think I prefer the Sydney approach to AOP, which uses Behaviors:

http://hoshi.fallingsnow.net/svn/sydney/trunk/lib/behavior/aop.rb

Regards,

Is there any documentation on this? The upper level README is just a
file manifest.

Ed


#7

On 11/28/05, Mark Collins-Cope removed_email_address@domain.invalid wrote:

Hi there,

I was wondering if there is any support (in the form of frameworks or
whatever) for AOP in Ruby?

There is Cut, as defined in RCR 321
http://www.rcrchive.net/rcr/show/321"

I’ve tried this out and it seems to work fairly well in my limited
exposure. Cuts are
transparent subclasses. While the technique in Christian’a reply
works, Cut is more broad based. You can reuse aspects by enclosing
them in modules, and apply the Cut class across ObjectSpace to have
system-wide aspects.

Ed


#8

m-lists wrote:

Christian L. wrote:

I thought aspects were baked into the language. You just have to
re-open a
definition like:
[… example elided …]

That’s not exactly the same thing as AOP is it (or a very special case)?
I mean, with AOP you should be able to define things like pointcuts to
apply advice to etc. What you described feels very much like a around
advice applied to a single method.

It is, but creating a general solution out of that is not a difficult
exercise. That’s the point, AOP lies very close to the surface of Ruby
code.

– Jim W.


#9

Christian L. wrote:

I like the Sydney stuff a little more too… Seems cleaner somehow.

The RCR sounded neat up until I got to: “A way to specify alternate
method-to-advice mappings” where it started to break down for me.

So one advice can be used for many methods. Sorry if I made it sound
more complicated than it is.

T.


#10

Christian L. wrote:

I thought aspects were baked into the language. You just have to
re-open a
definition like:

class A
def a_method
# do something
end
end

class B < A
alias old_a_method a_method

def a_method
puts “I’m an aspect”

old_a_method

end
end

Maybe I’m climbing up the wrong tree. Dependency injection and AOP
are
different problems aren’t they?

That’s not exactly the same thing as AOP is it (or a very special case)?
I mean, with AOP you should be able to define things like pointcuts to
apply advice to etc. What you described feels very much like a around
advice applied to a single method. If you would do that to all methods
you would like to advice with for example transactionality you would be
in for a lot of typing in contrast to doing it with pointcuts based on
regexp applied to class/method names.

/Marcus


#11

On 11/28/05, Mark Collins-Cope removed_email_address@domain.invalid wrote:

Hi there,

I was wondering if there is any support (in the form of frameworks or
whatever) for AOP in Ruby?

Nitro + Og support AOP, have a look at http://www.nitrohq.com

-g.