Created
May 24, 2011 14:16
-
-
Save chrisjpowers/988774 to your computer and use it in GitHub Desktop.
Ruby undef vs. remove_method
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
class A | |
def hello | |
"hello from A" | |
end | |
end | |
class B | |
def hello | |
"hello from B" | |
end | |
end | |
module Mixer | |
def hello | |
"hello from Mixer" | |
end | |
end | |
A.class_eval do | |
undef hello | |
include Mixer | |
end | |
B.class_eval do | |
remove_method :hello | |
include Mixer | |
end | |
A.new.hello #=> NoMethodError: undefined method "hello" -- undef banished this method from A forever?!?! | |
B.new.hello #=> "hello from Mixer" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment