4 ms·
'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
by tef__ 16y ago
'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.
- deleted 16y ago[deleted]