def a_method p "in distress" end alias :hero :a_method def a_method hero p "Saved by the hero" end
Here is a method in distress and it has been saved by a hero. But someone else doesn’t like how the story ends and decides to overwrite what the hero did.
alias :nemesis ? def ? #which method to call? p "Captured by the nemesis" end
Is it possible for the nemesis to overwrite what the hero did and have the final outcome be
"in distress" "Captured by the nemesis"
It seems like this would work without any more aliasing:
There isn’t any way for the nemesis to “unalias” and determine the old value of :a_method before the hero came along, however. The fact that Ruby doesn’t preserve history like that is the reason you need aliases in such override situations in the first place.