|
Re: class === class often false?: msg#01157lang.ruby.general
----- Original Message ----- From: "Bill Kelly" <billk@xxxxxxx> To: "ruby-talk ML" <ruby-talk@xxxxxxxxxxxxx> Sent: Monday, August 12, 2002 6:52 PM Subject: class === class often false? > 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 (some snips) > Just wondering if this behavior is intentional, and if so, why? I'll take a stab at this one. If I'm wrong at any point, someone please correct me. The === operator (method) may mean different things depending on what class it belongs to. That's no big news. When the receiver and the other operand (x === y) are both classes, it is (I think) essentially the same as saying: x.is_a? y So far, so good. Note also that if a class includes a module, it then has the "is a" relationship with that module, and an included module shows up in the list of ancestors. (Since a module is a kind of parent -- it's like a limited form of inheritance.) 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? Hal
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | class === class often false?, Bill Kelly |
|---|---|
| Next by Date: | Re: Primary Key Hash help, Jim Freeze |
| Previous by Thread: | class === class often false?, Bill Kelly |
| Next by Thread: | Re: class === class often false?, dblack |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |