Skip to content

Instantly share code, notes, and snippets.

@bachue
Created December 9, 2012 14:03
Show Gist options
  • Save bachue/4245021 to your computer and use it in GitHub Desktop.
Save bachue/4245021 to your computer and use it in GitHub Desktop.
Aquarium Hello world
require 'aquarium'
include Aquarium::Aspects
class A
def f
puts 'A#f'
end
def g
puts 'A#g'
end
end
Aspect.new :around, :calls_to => :all_methods, :for_types => [A], :method_options => :exclude_ancestor_methods do |join_point, object, *args|
p "Entering: #{join_point.target_type.name}##{join_point.method_name} for object #{object}"
result = join_point.proceed
p "Leaving: #{join_point.target_type.name}##{join_point.method_name} for object #{object}"
result # block needs to return the result of the "proceed"!
end
a = A.new
puts a.f.inspect
puts a.g.inspect
@bachue
Copy link
Author

bachue commented Dec 9, 2012

Result:

"Entering: A#f for object #<A:0x007f882296c718>"
A#f
"Leaving: A#f for object #<A:0x007f882296c718>"
"Entering: A#g for object #<A:0x007f882296c718>"
A#g
"Leaving: A#g for object #<A:0x007f882296c718>"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment