Skip to content

Instantly share code, notes, and snippets.

@marcgg
Created September 14, 2010 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marcgg/579420 to your computer and use it in GitHub Desktop.
Save marcgg/579420 to your computer and use it in GitHub Desktop.
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
@dmathieu
Copy link

Use alias instead of remove_method. That way you'll still have access to both of the methods.

@marcgg
Copy link
Author

marcgg commented Sep 14, 2010

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