From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2002-02-20T06:57:55+09:00 Subject: Re: Operator overloading and multiple arguments In article <20020219145252.C4142@atdesk.com>, Paul Brannan wrote: >On Wed, Feb 20, 2002 at 04:17:41AM +0900, Phil Tomson wrote: >> Anyway, I think it won't be a problem using '<=' for assignment in this >> case. Here's why: > >Okay. But be careful, because many operator have lower precedence than ><=. If you try to do anything slightly out of the ordinary with your >assignments, then you will get unexpected results. Yep. Already ran into that. I was going to override 'and' and 'or' so that they could be used in equations: a <= {b or c} b <= {d and f} ....but 'and' and 'or' have a lower precedence than '<=', so I had to change to using '*' and '+', like: a <= {b + c} b <= {d * f} It would kind of be nice to be able to specify a precedence for an overloaded operator, but that's a lot to ask for, I suppose. > >Some people have suggested using []= with no arguments as a redefinable >assignment operator. The pickaxe book lists []= as having the highest >precedence, but this doesn't make sense, since this would mean > > a[4] = 1 + 1 > >would not work as expected. Is this a bug in the book? Ruby in a Nutshell lists '[]' as being second only to '::' in precedence. Phil