Polymorphism

According to the Wikipedia article on polymorphism in the context of object oriented programming, “the primary usage of polymorphism is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior.” This means that if I have multiple types of players in a game, I can give them all a make_move function. When that function is called it can alternate whose turn it is, changing which player responds to the make_move function. Here’s an example.

class AI < Player
..def make_move
....perfect_move
..end
end

class Human < Player
..def make_move
....get_input
..end
end

In the above example both Human and AI classes inherit from a parent Player class with a function make_move. Both will respond to the same function call but will return different implementations.