Ryan Davis wrote:
> On Dec 29, 2008, at 17:13 , Yukihiro Matsumoto wrote:
> 
>> |== and != should not be able to contradict each other.
>> |
>> |Is this a bug? I looked at the code and it looks intentional. Should
>> |it be allowed?
>>
>> It's intentional.  Ruby's flexibility sometimes allows you to do some
>> nasty things.  Ruby consider you smart enough to avoid such
>> contradiction.
> 
> ok... but why?
As long as we have

  def != other
    !(self == other)
  end

by default with no core class defining != differently, everything stays
basically the same. Remember that you can already redefine things like
Fixnum#== in Ruby 1.8 - creating untracable bugs and mathematical
contradictions if you want:

  class Fixnum
    def == other # !> method redefined; discarding old ==
      true
    end
  end

  1 == 2  # => true

So Ruby has never been foolproof.

I admit that I have no idea how to argue for this logically, since when
!= and == mean "not equal" and "equal", we can deduce one from another.
I agree that nobody should feel encouraged by this to define
contradicting and confusing behavior.

But consider some DSL like RSpec:

    target.should_not == value

This can be written as

    target.should != value

in Ruby 1.9, reporting a different error message for each case. You can
also imagine uses for the now definable ! in such DSLs.

Ruby gives you the freedom do explore the possibilities of features that
even the language designer might now have had in mind. Ruby > matz :)

Defaults are a good thing. Written-in-stone rules are a bad thing. At
least for people who like to play with their code :) Panta rhei.

[murphy]