boddhisattva
boddhisattva

Reputation: 7380

Is Ruby a pure object oriented programming language even though it doesn't support multiple inheritance?

I know that to an extent substitutes the lack of multiple inheritance by allowing one to include multiple modules within a class.

Also, I'm not sure of all of the prerequisites of a pure OOP Language. From this article, they mention

a Ruby class can have only one method with a given name (if you define a method with the same name twice, the latter method definition prevails..

So does it mean that Ruby doesn't support overloading methods? If so, it still can qualify as a pure OOP language? What is the reason behind this as well?

Upvotes: 7

Views: 8738

Answers (3)

sk4l
sk4l

Reputation: 195

If multiple inheritance were the only "symptom" of a OOP language, then neither would Java, C#, Python, and many more be OOP languages.

What makes a language object-oriented in the first place are naturally objects. Everything is an object in ruby. The whole language is built on the concept of objects and data. Different objects can "communicate" between each other, you can encapsulate data, etc.

Take a look at this resource: Definitions for ObjectOriented.

Upvotes: 6

tadman
tadman

Reputation: 211540

There are several different families of object-oriented languages. If you're thinking of multiple inheritance and method overloading, you're probably coming from a C++ mindset where these things are taken for granted. These conventions came from earlier languages that C++ is heavily influenced by.

Ruby doesn't concern itself with the type of objects, but rather the methods they're capable of responding to. This is called duck typing and is what separates Smalltalk-inspired languages like Ruby from the more formal Simula or ALGOL influenced languages like C++.

Using modules it's possible to "mix in" methods from various sources and have a sort of multiple inheritance, but strictly speaking it's not possible for a class to have more than one immediate parent class. In practice this is generally not a big deal, as inheritance is not the only way of adding methods.

Method overloading is largely irrelevant in Ruby because of duck-typing. In C++ you might have various methods for handling string, int or float types, but in Ruby you'd have one that calls to_f on whatever comes in and manipulates it accordingly. In this sense, Ruby methods are a lot more like C++ templates.

Upvotes: 12

sawa
sawa

Reputation: 168071

In the first place, the problem of multiple inheritance makes sense only for an object oriented language. The very question of asking about multiple inheritance with Ruby itself proves that Ruby is an object oriented language.

Upvotes: 5

Related Questions