Skip to content

Instantly share code, notes, and snippets.

@rafael-fernandes
Created August 30, 2019 12:16
Show Gist options
  • Save rafael-fernandes/5971722179d5d63db460cd46d0353dc6 to your computer and use it in GitHub Desktop.
Save rafael-fernandes/5971722179d5d63db460cd46d0353dc6 to your computer and use it in GitHub Desktop.
#!/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