Created
December 9, 2012 14:03
-
-
Save bachue/4245021 to your computer and use it in GitHub Desktop.
Aquarium Hello world
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 | |
puts a.f.inspect | |
puts a.g.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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>"