Last active
August 29, 2015 14:14
-
-
Save leopoldodonnell/c036b6356d6bb5a60400 to your computer and use it in GitHub Desktop.
Monkey Patch a class without polluting the namespace and methods in a class
This file contains hidden or 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 ClassToMonkeyPatch | |
old_method = instance_method(:patched_method) | |
define_method(:patched_method) do |arg1, arg2, &block| | |
do_some_stuff | |
# delegate the rest to the old version of the method | |
res = old_method.bind(self).(arg1, arg2, &block) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment