Created
August 30, 2019 12:16
-
-
Save rafael-fernandes/5971722179d5d63db460cd46d0353dc6 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'aspector' | |
watcher = Aspector do | |
around(/.*/, except: Object.methods) do |proxy, *args, &block| | |
puts "before #{proxy.name} on #{proxy.receiver}" | |
proxy.call(*args, &block) | |
puts "after #{proxy.name} on #{proxy.receiver}" | |
end | |
end | |
class Person | |
def inst | |
"instance method" | |
end | |
def name | |
"Rafael" | |
end | |
end | |
watcher.apply(Person) | |
watcher.apply(Person, class_methods: true) | |
p = Person.new | |
p.inst | |
p.name | |
# Person.new.inst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment