Skip to content

Instantly share code, notes, and snippets.

@adelcambre
Last active May 17, 2017 00:06
Show Gist options
  • Save adelcambre/4c4b3c883f5098b1c2e996564cd13f23 to your computer and use it in GitHub Desktop.
Save adelcambre/4c4b3c883f5098b1c2e996564cd13f23 to your computer and use it in GitHub Desktop.
Module.new do
def prepend(m=nil, &blk)
if block_given?
super(Module.new(&blk))
else
super
end
end
end.tap { |pre| Module.prepend pre }
class Foo
def bar
puts "class"
end
end
Foo.prepend do
def bar
puts "prepended"
super
end
end
module Bar
def bar
puts "module"
super
end
end
Foo.prepend Bar
Foo.new.bar # => module
# prepended
# class
@adelcambre
Copy link
Author

@rwz Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment