Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is ruby a pure object oriented programming language even though it doesn't support multiple inheritance? If so how?, please explain.

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 Lanaguage ? If so, kindly explain the reason behind this as well.

Thank you.

like image 302
boddhisattva Avatar asked Jul 16 '13 15:07

boddhisattva


People also ask

Is Ruby a pure object-oriented programming language?

Ruby is a very pure object-oriented language: all values are objects, and there is no distinction between primitive types and object types as there are in many other languages. In Ruby, all objects inherit from a class named Object and share the methods defined by that class.

Why Ruby is object-oriented programming?

Ruby supports the OOP paradigm by allowing the creation of classes and its objects. Like we said before, objects are the instances of a class and a class is like the blueprints for the object. A class lists out the attributes and defines the behavior for the object while the object is the real world representation.

Is Ruby pure OO?

Ruby is a pure OO language that can masquerade as a procedural one. It has no functions, only method calls. In a Ruby method the receiver, also called self , is a hidden argument like this in C++. A def statement outside of a class definition, which is a function in Python, is actually a method call in Ruby.

Which is the pure object-oriented programming language?

int, long, bool, float, char, etc as Objects: Smalltalk is a “pure” object-oriented programming language unlike Java and C++ as there is no difference between values which are objects and values which are primitive types. In Smalltalk, primitive values such as integers, booleans and characters are also objects.


2 Answers

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.

like image 120
tadman Avatar answered Nov 15 '22 06:11

tadman


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.

like image 27
sk4l Avatar answered Nov 15 '22 06:11

sk4l