A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/ruby/polymorphism-in-ruby/ below:

Polymorphism in Ruby - GeeksforGeeks

Polymorphism in Ruby

Last Updated : 12 Jul, 2025

In

Ruby

, one does not have anything like the variable types as there is in other programming languages. Every variable is an "object" which can be individually modified. One can easily add methods and functions on every object. So here, the Object Oriented Programming plays a major role. There are many pillars of Object Oriented Programming in every other programming language, like Inheritance, Encapsulation etc. One of these pillars is Polymorphism.

Polymorphism

is a made up of two words

Poly

which means

Many

and

Morph

which means

Forms

. So Polymorphism is a method where one is able to execute the same method using different objects. In polymorphism, we can obtain different results using the same function by passing different input objects. One can also write the If-Else commands but that just makes the code more lengthy. To avoid this, the programmers came up with the concept of polymorphism. In Polymorphism, classes have different functionality but they share common interference. The concept of polymorphism can be studied under few sub categories.

  1. Polymorphism using Inheritance
  2. Polymorphism using Duck-Typing


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4