From: Colin Bartlett Date: 2010-05-13T01:16:13+09:00 Subject: Re: In Ruby, can the coerce() method know what operator it is th On Tue, May 11, 2010 at 4:46 PM, Caleb Clausen wrote: ...[for coerce] > Generally, you want to return an array containing (a representation of) other first > and then (a representation of) self. I've been wondering how to express concisely what you've concisely expressed there! (I'm referring to the "(a representation of)" bit for both other and self.) > That helps ensure that when the caller calls >  other.op self > it won't end up with the arguments backwards. > So operators like - and / can work correctly. > If you return self first and then other, + and * will work but, not - and /. With a pedantic former maths student's hat on: If you return self first and then other: + will (probably?) work because (almost?) all uses of + are commutative (I've never seen a non-commutative use of +, but you never know!); * will probably work, but may not if the use of * is not commutative (for example matrix multiplication?); - and / and ** (probably?) won't work because (almost?) all uses of them are non-commutative. (I've never seen commutative uses, but ...); and if <=> is defined for (a representation of) other and (a representation of) self, that probably won't work either!