Created
December 9, 2012 14:11
-
-
Save bachue/4245070 to your computer and use it in GitHub Desktop.
Aquarium can't deal with new methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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