Skip to content

Instantly share code, notes, and snippets.

@osyo-manga
Created October 7, 2015 17:15
Show Gist options
  • Select an option

  • Save osyo-manga/6eaa17d66b61e8846446 to your computer and use it in GitHub Desktop.

Select an option

Save osyo-manga/6eaa17d66b61e8846446 to your computer and use it in GitHub Desktop.
module MethodWrapper
def wrap name, &block
prepend(Module.new do
define_method name do
super_ = proc { super() }
Object.new.instance_eval do
define_singleton_method :super_ do
super_.()
end
instance_eval &block
end
end
end)
end
end
class X
extend MethodWrapper
def homu
p :homu
end
wrap :homu do
p :mami
super_()
end
end
X.new.homu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment