From: Christoph Date: 2002-06-14T02:05:07+09:00 Subject: Re: Relational operators redux (returning RHS) "Austin Ziegler" wrote in .... > is fundamentally sound (warning; the following is untested > air-code). Still way above my standard;-) > > alias :oeq, :== > > def == (other) > if other.nil? > false > elsif oeq(other) > other > else > false > end > end This would also imply false == false # => false > > It would be necessary to replace NilClass#== with > > class NilClass > def ==(other) > false > end > end > > to handle nil on the LHS. > > If we have the NilClass replacement and the first code in Fixnum, > then: > > x = 5 > y = 6 > > p x == x #=> 5 > p x == y #=> false > p x == nil #=> false > p nil == x #=> false > > Unfortunately, because != is simply syntactic sugar for ! (x == x), > the != tests aren't as clean: > > p x != x #=> false > p x != y #=> true > p x != nil #=> true > p nil != x #=> true > > This means that if this were to become normative behaviour, x != y > would produce surprising results. I'm not quite sure what the proper > answer to this is, but it's just a thought or two. > > As I said, I *like* the idea that nil isn't equal to anything, > including nil. I don't like this idea, and I am not so sure if the C-heritage of nan = 0.0 / 0.0 nan.equal? nan # => true but nan == nan # => false is really such a good idea. /Christoph