Created
September 14, 2010 17:26
-
-
Save marcgg/579420 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
class A | |
def something | |
puts "something in A" | |
end | |
end | |
module B | |
def self.included(klass) | |
klass.send :remove_method, :something | |
end | |
def something | |
puts "something in B" | |
end | |
end | |
a = A.new | |
a.something | |
A.send(:include, B) | |
a = A.new | |
a.something | |
# Displays: | |
# something in A | |
# something in B |
Here I didn't really care about being able to access the old method, but you're right!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use alias instead of remove_method. That way you'll still have access to both of the methods.