Let's say your coworker monkeypatches the Fixnum class and redefines the + method to subtract instead of add:
class Fixnum
def +(x)
self - x
end
end
>> 5 + 3
=> 2
Your problem is you want to access the original functionality of the + method. So you drop this code in before his in the same source file. It aliases the + method to "original_plus" before he monkeypatches it.
class Fixnum
alias_method :original_plus, :+
end
class Fixnum
def +(x)
self - x
end
end
Now you can access the original functionality of the + method through original_plus
>> 5 + 3
=> 2
>> 5.original_plus(3)
=> 8
But what I need to know is this:
Is there any other way of loading this alias BEFORE his monkeypatch loads besides sticking it into the same source file that he modified?
There are two reasons for my question:
- I may not want him to know that I have done this
- If the source file is altered so that the alias ends up BELOW the monkeypatch, then the alias will no longer produce the desired result.