Polymorphism is one of the core concepts of object-oriented programing(OOP). It might sounds daunting, but nothing to worry. it's just a long word for a very simple concept.
First of all, Polymorphism means “many shapes” in Greek. Please keep it in mind. It could be of help later.
Kindly ignore the syntax and pay no attention to precise technical points. It's about a concept.
When to use
We use Polymorphism when you want each instance to behave in its own way though they call a common method.
How to define
Just put a method which contains nothing in a class so that you can make every instance generated from the class act in its own way.
class Car name = def run end end
Ferrari instance which is generated form the Car class run 200km/h.
Toyota Corolla instance which is also generated from the Car class run 60km/h.
To simply put, the concept of Polymorphism is that "same name, different befaviour" .
class Animal name = def makeSounds end end
Cat instance which is generated from the Animal class makeSounds ”meow”.
Bird instance which is also generated from the Animal class makeSounds “chirp".
So polymorphism is the ability of an object to take on many shapes and to call a common method which differs depending on its own shape.
I think now you got it.
Hope this helps and makes it clear.