Skip to content

Instantly share code, notes, and snippets.

@nouse
Created March 8, 2015 02:56
Show Gist options
  • Save nouse/175cb14ee0c13f867fc7 to your computer and use it in GitHub Desktop.
Save nouse/175cb14ee0c13f867fc7 to your computer and use it in GitHub Desktop.
ruby AOP
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