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.
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
输出:
记录鲁弗斯的吠叫!
鲁弗斯狗叫了!
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
发布评论
评论(5)
我在两三年前在大学项目中尝试过 Aquarium gem。效果很好,项目的目的是与 AspectJ 进行比较,看看它是否能够像 AspectJ 一样完成所有事情。当时 AspectJ 所具备的很多功能都缺失了。但现在我看到添加了很多东西,因此值得再次尝试。
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.
AspectR(最后一个版本看起来像是 2002 年)——最初是 Ruby 中的规范 AOP 库。
Facets - 具有一些 AOP 功能。
AspectR (last release looks like in 2002) - originally the canonical AOP library in Ruby.
Facets - has some AOP functionality.
使用 Ruby 2.0+,您不一定需要框架:
输出:
With Ruby 2.0+, you don't necessarily need a framework:
Output:
您没有指定任何评估不同框架的标准,所以这是我在 Google 上花了 3 秒后发现的一个标准:水族馆。
另一个,由@Telemachus建议:凝视者。
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.
无耻插件:aspector 可能就是您正在寻找的。它允许您定义方面,然后应用于一个或多个目标。
Shameless plug: aspector could be what you are looking for. It allows you to define aspect and then apply to one or more targets.