How is Ruby more object-oriented than Python? How is Ruby more object-oriented than Python? ruby ruby

How is Ruby more object-oriented than Python?


If you take the Python from 1993 and compare it with Ruby then the latter is more object oriented. However, after the overhaul in Python 2.2 this is no longer true. I'd say that modern Python is as object oriented as it gets.


One example that's commonly given is len, which in Python is a built-in function. You may implement a special __len__ method in your objects which will be called by len, but len is still a function. In Ruby, objects just have the .length property/method so it appears more object oriented when you say obj.length rather than len(obj) although deep under the hood pretty much the same thing happens.

That said, over the years Python have moved towards more object-orientation. Currently all objects (and implicitly user-defined objects) inherit from the object class. Meta-classes have also been added, and many of the built-in and core library classes have been organized into hierarchies with the help of ABCs (Abstract Base Classes).

In my heavy usage of Python I have never found it lacking in the OO department. It can do everything I want it to do with objects. True, Ruby feels somewhat more purely OO, but at least in my experience this hasn't been a really practical concern.


From WikiVS,

… where in Ruby all functions and most operators are in fact methods of an object, a number of Python functions are procedural functions rather than methods.

The following interview with Matz, the creator of Ruby, provides additional context to your question and the point above.

Stewart: Let's start with a little history. Why did you decide to write Ruby?

Matz: Back in 1993, I was talking with a colleague about scripting languages. I was pretty impressed by their power and their possibilities. I felt scripting was the way to go.

As a long time object-oriented programming fan, it seemed to me that OO programming was very suitable for scripting too. Then I looked around the Net. I found that Perl 5, which had not released yet, was going to implement OO features, but it was not really what I wanted. I gave up on Perl as an object-oriented scripting language.

Then I came across Python. It was an interpretive, object-oriented language. But I didn't feel like it was a "scripting" language. In addition, it was a hybrid language of procedural programming and object-oriented programming.

I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why I decided to design my own language.