How can you make safe, backward compatibility "reverse-monkeypatch" in Ruby?

If your colleague “opens” the “monkeypatches” class in Ruby and overrides some important functions that you need to use, how do you access this original function other than pre-monkeypatched without breaking the system that already relies / has depending on its monkey-loaded definition?

+4
source share
3 answers

Given an example of overriding a method, if you can load some code before downloading its monkey patch, you can use this method.

class Fixnum alias_method :original_plus, :+ end class Fixnum def +(x) self - x end end >> 5 + 3 => 2 >> 5.original_plus(3) => 8 
+5
source

I recently saw this on the rubyflow channel, my simple library that allows you to define top-level constants called aikidoka . Without any details on how / what happens to the monkey, it is a little difficult to help. In theory, although you could use a similar approach to name class space with monkey fixes, so you can access it and the original independently.

+3
source

It depends on what functionality has been changed and how, but something that implements, for example, the Jim Wienrich BlankSlate class can help:

0
source

All Articles