basically overwrites everything that may have been defined beforehand (such as other scripts that aliased the same method)I'm not sure if there is even a solution to this problem, short of forcing every method in the default scripts to call super (if they do not already do so) because any method is fair game for aliasing, and making sure if you do any inheritance of your own, make sure there are super calls.class Game_Actor def on_battle_end super #<------- this end alias on_battle_end_one on_battle_end def on_battle_end on_battle_end_one #add your logic here endend
PS: You might need to delete the def from the succeeding scripts though so that only one script has it.![]()
The main problem of this way is that it only works once. If you have two scripts that extend the method this way, one of them will inevitably get lost. Of course you can weigh the risk of this happening in praxis, with aliasing you keep out of harm's way - if it wasn't for the issue Tsukihime stated.
Something like this would be problematic:
class A def test p 'A' endendclass B < A def test super # Prints 'A' p 'B' endendclass A alias :th_old_test :test def test th_old_test p 'A2' endend class B def test super # Extend test. Without knowing B already defines test, p 'B' is lost p "B52" endendb = B.newb.test # Calls B.test, which calls super, which is A.test (including its aliased version)
Alias will look at the value of self lexically where the aliased keyword lies. Alias_method use the value of self during runtime which may be a subclass where the call is lexically located.
def rename alias_method :new_method, :testend class A def test puts 'A' end renameend