From: Rudolf Polzer Date: 2003-08-11T06:15:17+09:00 Subject: Re: Ruby and OOP-design (question of an old "procedural person" ;) Scripsit ille �Brian Candler� : > On Mon, Aug 11, 2003 at 02:02:33AM +0900, dblack@superlink.net wrote: > > > Does ruby not have exclusive or? I can't remember at the moment. If it > > > did, I think the top is the same > > > as: > > > > > > unless a.nil? ^ b.nil? > > > > > > Which is still somewhat unclear, I agree. > > > > I, however, no long agree with myself :-) I just forgot about ^. > > However ^ is overloaded, so although it works when comparing false/true with > false/true, it doesn't with other things; especially since it doubles up as > a bitwise numeric operator too. BTW: why do all C-like languages lack the ^^ operator (boolean XOR)? > irb(main):001:0> 5 ^ false > TypeError: cannot convert false into Integer > from (irb):1:in `^' > from (irb):1 > > But it does treat 'nil' as 'false'. So you could say: > > if (a && true) ^ (b && true) if !a ^ !b # since a xor b == (not a) xor (not b) Well, my common C idioms for this case are: boolean XOR: !a ^ !b obfuscated boolean XOR: !a!=!!!b /* no, I am not using that */ convert to boolean: !!a They all work in Ruby. -- L: N�per er�t medic�s nunc �st visp�llo Di�ulus: D: Fr�her war er Arzt, nun ist Diaulus Totengr�ber: L: Qu�d visp�llo fac�t - f�cerat �t medic�s. D: Was er als Totengr�ber macht - tat er schon als Arzt. [Martial]