July 2011
Intermediate to advanced
400 pages
8h 46m
English
One way of avoiding ambiguity when you use similarly named methods from multiple modules is to alias those methods. An alias is a copy of an existing method with a new name. You use the alias keyword followed by the new name and then the old name:
alias happyexpression expression
You can also use alias to make copies of methods that have been overridden so that you can specifically refer to a version prior to its overridden definition:
alias_methods.rb
module Happy def Happy.mood return "happy" end def expression return "smiling" end alias happyexpression expression end module Sad def Sad.mood return "sad" end def expression return "frowning" end alias sadexpression expression end class Person include Happy include Sad attr_accessor ...
Read now
Unlock full access