What frameworks exist to add AOP to Ruby?
5 Answers
With Ruby 2.0+, you don't necessarily need a framework:
module BarkLogger
def bark
puts "Logging #@name's bark!"
super
end
end
class Dog
prepend BarkLogger
def initialize(name)
@name = name
end
def bark
puts "#@name the dog says bark!"
end
end
Dog.new("Rufus").bark
Output:
Logging Rufus's bark!
Rufus the dog says bark!

- 45,670
- 22
- 127
- 172
-
In my opinion this is a great solution. It doesn't require any gems. – Robbin Voortman Mar 07 '17 at 10:01
You haven't specified any criteria for evaluating different frameworks, so here's one that I found after 3 seconds on Google: Aquarium.
Another one, suggested by @Telemachus: gazer.
-
2Yup, I did about the same: Google suggested [Aquarium](https://github.com/deanwampler/Aquarium) as you say and also [gazer](https://github.com/teejayvanslyke/gazer). – Telemachus Mar 22 '11 at 15:42
-
-
@Andrew the github page that Telemachus linked shows (much) more recent activity, FWIW. – Matt Ball Nov 30 '11 at 03:35
-
It might be worth mentioning here, that Aquarium is not thread-safe: https://github.com/deanwampler/Aquarium/issues/39 – Andrzej Krzywda Apr 20 '13 at 07:55
Shameless plug: aspector could be what you are looking for. It allows you to define aspect and then apply to one or more targets.

- 507
- 4
- 11
I tried 2 or 3 years ago Aquarium gem at university project. Worked nice, aim of project was comparing with AspectJ, to find out if it is capable of all things as AspectJ. At that time a lot of functionality, which AspectJ was capable of, was missing. But now I see a many things were added, so it's worth a try again.

- 641
- 4
- 5
AspectR (last release looks like in 2002) - originally the canonical AOP library in Ruby.
Facets - has some AOP functionality.

- 7,070
- 3
- 38
- 28