Suppose you want to rename a Ruby class name, but don’t want to go through the hassle of renaming all the files and class references in the code. An easy solution is to alias the class (classes are just constants in Ruby). If we have a BaseballPlayer class that we want to alias with Athlete, we can just set the BaseballPlayer constant equal to Athlete:
class BaseballPlayer end BaseballPlayer = Athlete
After the BaseballPlayer constant is aliased with Athlete, we can initialize BaseballPlayer objects with the Athlete keyword.
# This works >> a = Athlete.new # This also still works >> b = BaseballPlayer.new
Aliasing a model with a class name that has a different meaning probably is not good, but this solution is good for classes that are renamed with a synonym (i.e. changing a Kid class to a Child class).