Last active
May 17, 2017 00:06
-
-
Save adelcambre/4c4b3c883f5098b1c2e996564cd13f23 to your computer and use it in GitHub Desktop.
This file contains 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
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rwz Fixed.