remove_method
should work in most cases. But if your alias_method
overwrites an existing method, you may need to save the original via a separate alias_method
call.
# assuming :contains? is already a method
alias_method :original_contains?, :contains?
alias_method :contains?, :include?
Then to restore the original state:
alias_method :contains?, :original_contains?
remove_method :original_contains? # optional
Note also that modifying a class that's used in multiple threads is prone to race conditions. And if you're trying to disallow libs from using the alias, you can't prevent that if you're calling those libs' methods while the alias exists. We might see a way to do this in ruby 2.0: http://yehudakatz.com/2010/11/30/ruby-2-0-refinements-in-practice/
It would be helpful if you could say why you want to remove the alias. If the method name did not exist before, no other libs should be affected by your monkey-patch. Also, you should consider subclassing String
(or delegating to a string instance) rather than patching String
.