From: Bill Kelly Date: 2002-08-13T10:47:45+09:00 Subject: Re: class === class often false? Hi Hal, From: "Hal E. Fulton" > > From: "Bill Kelly" > > > I'm just noticing that some classes return true when testing > > themselves with #===, while others return false. For instance: > > > > (ruby 1.6.6 (2001-12-26) [i586-mswin32]) > > irb> Bignum === Bignum > > false > > irb> Kernel === Kernel > > true > > irb> Object === Object > > true > > irb> Comparable === Comparable > > false > [...] > Then note that there is some circularity in Ruby's > object paradigm. Everything is an object. Even the > class Class is an object. Note that these are > both true: > > Class.is_a? Object > Object.is_a? Class > > I have spent many hours lying in bed thinking about > this. :) :-) > I think the cases where you're getting a "true" for > "klass === klass" are the ones where the circularity > is asserting itself. > > For example: Kernel is-a Object, but Object is-a Kernel. > Or more indirectly: Kernel is-a Module is-a Object is-a > Kernel. There are probably other paths (through Class, > which is-a Module). > > For the cases where you get false, I can't see any > way of tracing back to oneself. For example, Bignum > is-a Object, or is-a Class, or is-a Kernel... but these > don't ever lead back to Bignum. > > Help any? Interesting... further tests in irb seem to support your hypothesis. Thanks! . . . Actually what I finally realized was that Ruby was already doing what I wanted in case statements. I'm dealing with an instance, so === doing is_a? is just what I want after all. I had been trying: case some_instance.class when Bignum etc. Where I can simply do (of course) case some_instance when Bignum etc. Which is great (as usual.) Regards, Bill