Skip to content

Instantly share code, notes, and snippets.

@chrisjpowers
Created May 24, 2011 14:16
Show Gist options
  • Save chrisjpowers/988774 to your computer and use it in GitHub Desktop.
Save chrisjpowers/988774 to your computer and use it in GitHub Desktop.
Ruby undef vs. remove_method
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