3 ms·
Sorted mandates the type you give it implements __iter__, aka that it is iterable. Ruby defines sort as a method on Enumerable. The difference is that most lik
by dwaite 5y ago
Sorted mandates the type you give it implements __iter__, aka that it is iterable. Ruby defines sort as a method on Enumerable.
The difference is that most likely that CPython and CRuby started with different capabilities to map native implementations into the language.
The biggest difference between the two is python adds more functions into the global namespace, while Ruby pushes pretty hard to encapsulate logic within types.
- remram 5y agoThe discussion is about how to provide additional functionality. To be sortable, you collection has to be a collection, and it has to have comparable elements. That has to be provided by the type itself. The difference between Python and Ruby is how to add more functions. If you make a library to sort collections (or format phone numbers), the Ruby way is to monkey-patch collections (or numbers). Whereas the Python way is to offer a free function that takes an iterable (or number). This is what we are discussing. Of course Python classes have methods.