Skip to content

Instantly share code, notes, and snippets.

@bachue
Created December 9, 2012 14:11
Show Gist options
  • Save bachue/4245070 to your computer and use it in GitHub Desktop.
Save bachue/4245070 to your computer and use it in GitHub Desktop.
Aquarium can't deal with new methods
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
a.f
a.g
class A
def h
puts 'A#h'
end
end
a.h # NO AOP code will be called here
# 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>"
# A#h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment