From: William Djaja Tjokroaminata Date: 2002-04-13T01:18:03+09:00 Subject: Re: Why Object#class Is Inconsistent in "==" and "case"? In the previous example by Guy Decoux, module MyModule .... case obj when MyClass # line NNN .... end end in Ruby, line NNN evaluates to "MyClass === obj" and not "obj === MyClass"? Is there any documentation on this and what is the rationale? Again, does this conform to the Priciple of Least Surprise or just some additional Ruby tricks that I have to memorize? (Last time it was Array.new (n, Hash.new) creates an array of n references of the single hash object, which is not useful in practice.) Why can't we make "MyClass === obj" and "obj === MyClass" to behave in the same way so that we don't have to deal with this extra peculiarity? (We can simply define Object#== is true for identical objects and Object#=== is true for identical object classes, just like the kind_of? method.) Again, it seems that by using == and if-elsif-else construct everything is natural; but once we use the case statement, there are too many nitty-gritty details that may make the case statement really dangerous. Based on this, probably case statement should be degraded to second class Ruby construct and the if-elsif-else as the first class as there may be arbitrary objects that randomly redefine the === method. Regards, Bill ========================================================================== Dave Thomas wrote: > You're using Module#===, not Object#=== in your example. > Dave