Skip to content

Instantly share code, notes, and snippets.

@YanhaoYang
Created May 21, 2016 08:42
Show Gist options
  • Save YanhaoYang/c3b5a907336567b1f54bfc9792a570c6 to your computer and use it in GitHub Desktop.
Save YanhaoYang/c3b5a907336567b1f54bfc9792a570c6 to your computer and use it in GitHub Desktop.
Redefine a method in a module
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