From: Nokan Emiro Date: 2013-01-26T07:52:51+09:00 Subject: limitations --e89a8fb1f27a5ada4004d424c9a2 Content-Type: text/plain; charset=UTF-8 Hi, Is there any way to somehow redefine operations like '&&' between my objects? '&&' is not defined as a method so I can't just overload it. (Ruby does not care if an object responds to :&&, it is simply not used.) Operators with higher precedence than '&&' usually work fine -- except '[]='. Seems like above '&&' it is the object's responsibility to do operations and below that line it is the language itself that enforces the rules. But is there a way to define custom code what should de done by an expression like 'x && y'? The same limitation bothers me with '||', and with 'and', 'or' and 'not'. (Yes, I know that they are not operators but designed to be flow control keywords, however they are often used as operators...) At the same time I'm struggling with the []=. The strange thing with this is that the return value of the []= method is abandoned by Ruby but I expected it to be the value of the expression that the []= method returns: class X def []=(key, value) "I want to be the value!!" end end x = X.new x[123] = 456 #=> 456 The value of the last expression is 456, and not the string. I'd like to get back the whole x object instead of the right hand side value here. Yes, I know that the value of assignments is the rhs value, but assignments in general are out of the scope of an object, while []= is an exceptional one. It is done by the object itself, so it would be logical to give the power to the object to decide the value of the operation. Is this a deliberate behaviour or just nobody cares the value of it? --e89a8fb1f27a5ada4004d424c9a2 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

Is there any way to somehow redefine operation= s like '&&' between my objects?
'&&' is= not defined as a method so I can't just overload it. =C2=A0(Ruby does = not care
if an object responds to :&&, it is simply not used.) =C2=A0Op= erators with higher precedence
than '&&' usually = work fine -- except '[]=3D'. =C2=A0Seems like above '&&= ' it is the object's
responsibility to do operations and below that line it is the language= itself that
enforces the rules. =C2=A0But is there a way to defi= ne custom code what should de done by
an expression like 'x &= amp;& y'?

The same limitation bothers me with '||', and w= ith 'and', 'or' and 'not'.
(Yes, I know t= hat they are not operators but designed to be flow control keywords,
however=C2=A0they are=C2=A0often used as operators...)

<= /div>
At the same time I'm struggling with the []=3D. =C2=A0The str= ange thing with this is
that the return value of the []=3D method= is abandoned by Ruby but I expected
it to be the value of the expression that the []=3D method returns:

class X
=C2=A0 def []=3D(key, value)
=
=C2=A0 =C2=A0 "I want to be the value!!"
=C2=A0 en= d
end
x =3D X.new
x[123] =3D 456 =C2=A0 #=3D> 456
The value of the last expression is 456, and not the string. = =C2=A0I'd like to get back the whole
x object instead of the = right hand side value here. =C2=A0Yes, I know that the value of assignments=
is the rhs value, but assignments in general are out of the scope of a= n object, while []=3D
is an exceptional one. =C2=A0It is done by = the object itself, so it would be logical to give the
power to th= e object to decide the value of the operation. =C2=A0Is this a deliberate b= ehaviour or
just nobody cares the value of it?

--e89a8fb1f27a5ada4004d424c9a2--