RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

aspect4r - Aspect Oriented Programming for Ruby

I am releasing my first gem - aspect4r. It allows one to extract common logic from multiple methods using before_method/after_method/around_method etc. It also provides a approach to split large methods into small pieces. I hope you guys find it useful. It might undergo some API changes before 1.0 after I put it in use in one of my projects. I’ll also be doing some benchmark testing next and improving its internals.

Comments

There is a good bit more to AOP then just wrappers. To that end you might be interested in http://github.com/rubyworks/cuts/blob/master/RCR.textile.

Even so, just for wrappers, also check out http://github.com/rubyworks/mixers/blob/master/lib/mixers/advisable.rb

Thank you for the information. I’ll see if I can borrow something from them.

IMHO, even though AOP means a lot more than method wrappers, Ruby’s programming model and its meta-programming support make it trivial to do other parts of AOP. An easy-to-use method wrapper can be the missing piece of AOP support in ruby.

For example, below code adds logging aspect to do_* of SomeController. module LoggingAspect include Aspect4r

before_method(instance_methods.select{|m| m=~ /do_/}) do # log request parameters end end

SomeController.send(:include, LoggingAspect) </code>

Fully agree. Ruby’s meta-programming capabilities do go along way in this regard.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in