Call original method when monkey patching
Ruby offers monkey patching methods in order to change the behavior of a library if there's no better way.
We can call the method we're overriding inside our monkey patch:
Copyclass Foo def bar(argument) 'Hello' + argument end end module FooExtensions def bar super(' in my') + ' World' end end class Foo prepend FooExtensions # the only change to above: prepend instead of include end Foo.new.bar # => 'Hello in my World'
As mentioned, monkey patches are usually a threat to your code quality, so try to avoid them if possible.
Further readings
For a better understanding have a look at this article.
Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.