Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In Ruby calling a method on an object basically sends a message to the object with the name of the method and the arguments. You can hook into the dispatch code and do pretty much whatever you want with that message at the class level. I don't know the internals of Python's method dispatch that well, so I can't say how it compares in that regard.


Are you referring to Ruby's method_missing? As I understand it's about the same as Smalltalks #doesNotUnderstand:.

Python doesn't have an equivalent, but it does have __getattr__, which is arguably more powerful but less convenient.


I believe Python's __getattr__() and __setattr__() allow you do the same thing, but I don't know enough Ruby to say for sure :-)


You couple those with ruby's method_missing and then you have some interesting functionality. But basically the way that Ruby handles operator overloading and function accessing is a lot cleaner than pythons. It would be pretty nice to get rid of a lot of the dunders.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: