From: Robert Klemme Date: 2003-09-23T16:12:57+09:00 Subject: Re: Operator overloading "Johann Hibschman" schrieb im Newsbeitrag news:41b772c.0309221105.26d32b4f@posting.google.com... > "Robert Klemme" wrote in message news:... > > > You can't. And you don't need to. As others pointed out already, Ruby > > treats all the assignment arithmetic operators as shortcuts and invokes > > the appropriate operator. So > > Er. "You don't need to" is rather extreme. What about numerical cases? > > i.e., if m is a large matrix, then "m += 1" and "m = m + 1" are rather > different beasts, since the "obvioius" interpretation of the first involves > simply incrementing the matrix in place, while the second involves a > copy. > > Is there a standard work-around for this? Resort to methods with proper names (like "add!", "mult!" etc. Convention is, that an exclamation mark denotes methods that modify the receiver). Personally I feel very comfortable with Ruby not encouraging overloading operators all the time as C++ does. Readability doesn't always benefit from overloading. And there is nothing that can't be achieved with a method call (from a functional perspective). Regards robert