Created
March 8, 2015 02:56
-
-
Save nouse/175cb14ee0c13f867fc7 to your computer and use it in GitHub Desktop.
ruby AOP
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
class A | |
def a | |
puts "a" | |
end | |
end | |
module Logger | |
def log(method_name) | |
m = self.instance_method(method_name) | |
undef_method method_name | |
define_method method_name.to_s do | |
puts "start" | |
m.bind(self).call | |
puts "end" | |
end | |
end | |
end | |
A.extend Logger | |
A.log :a | |
A.new.a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment