Created
May 21, 2016 08:42
-
-
Save YanhaoYang/c3b5a907336567b1f54bfc9792a570c6 to your computer and use it in GitHub Desktop.
Redefine a method in a module
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
module M1 | |
def hi | |
puts "hi in M1" | |
end | |
end | |
class A | |
include M1 | |
def ha | |
puts "ha" | |
end | |
end | |
a = A.new | |
a.hi | |
# => hi in M1 | |
a.ha | |
# => ha | |
module M2 | |
def hi | |
puts "hi in M2" | |
super | |
end | |
def ha | |
puts "ha in M2" | |
end | |
end | |
A.send :include, M2 | |
a.hi | |
# => hi in M2 | |
# => hi in M1 | |
a.ha | |
# => ha |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment