开发者

Aspect Oriented Programming in Ruby [closed]

开发者 https://www.devze.com 2023-02-18 05:28 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

开发者_C百科

Closed 8 years ago.

Improve this question

What frameworks exist to add AOP to Ruby?


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!


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.


Shameless plug: aspector could be what you are looking for. It allows you to define aspect and then apply to one or more targets.


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 (last release looks like in 2002) - originally the canonical AOP library in Ruby.

Facets - has some AOP functionality.

0

精彩评论

暂无评论...
验证码 换一张
取 消