News for hackers. Stuff that matters.
Re:Ruby is beautiful (but I'm moving to Python) by tef__ on Sunday November 28, 2010 @01:48PM (#1947887)
'I love that I can define + for any object in Ruby and that doing so gives me += for free.'

fwiw: this works in python too

>>> class Foo(object): ... def __add__(self, x): ... print "%s+%s"%(self,x) ... >>> a = Foo() >>> a+=8 <__main__.Foo object at 0x657d0>+8 >>>

You can override __iadd__ separately too.

There are no comments on this comment yet.