Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RubyForge-18458] Add :around_and_return advice? #23

Open
hedgehog opened this issue Jan 29, 2010 · 1 comment
Open

[RubyForge-18458] Add :around_and_return advice? #23

hedgehog opened this issue Jan 29, 2010 · 1 comment

Comments

@hedgehog
Copy link

Date:2008-02-28 15:02
Priority:1
Submitted By:Dean Wampler (deanwampler)
Assigned To:Dean Wampler (deanwampler)
Category:Advice handling
State:Open
Summary:Add :around_and_return advice?

Detailed description

It's a common mistake to forget that around advice needs to return something appropriate. For example, the following method-tracing advice block probably doesn't do what you intended:

p "entering #{join_point.inspect}"
join_point.proceed
p "leaving #{join_point.inspect}"

It looks simple enough, but the block will return the result of p, which is nil, rather than the result
of calling proceed.

This new advice type would capture internally whatever proceed returned and use that value as the result after the block finishes. It would allow the above advice to work as intended.

I'm not sure this is the best solution to this common problem, but I've made this mistake too, so it's easy to do!

@hedgehog
Copy link
Author

Yes this is definitely a gotcha I ran into and for AOP newbies can make it confusing to work out what is going on.

An alternative option might be to allow an advised object to implements a return_on_advise(jp, obj, args) method that is called if around
May not work. May just have to make this type of example prominent and live with errors from time to time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant