For some reason my alias_method_chain doesn’t want to work and I have no idea why. Can anyone explain to me why the following won’t work?
[2] pry(main)> Client.respond_to? :mapping
=> true
[3] pry(main)> Client.alias_method_chain :mapping, :safety
NameError: undefined method `mapping' for class `Client'
To get alias method chain for object of some class you should call
alias_method_chainon class itself and not on its instance. If you want to make chain of class methods the same rule applies: you should callalias_method_chainon class’s singleton class that can be obtained like that:In that case
Clientis an instance ofklassclass (that hasClassclass as its superclass).Resulting example of class methods chain can be the following: