From: "David A. Black" Date: 2004-07-08T06:04:43+09:00 Subject: Re: Class#=== has interesting results Hi -- On Thu, 8 Jul 2004, Charles Comstock wrote: > On Thu, 8 Jul 2004, David A. Black wrote: > > > Hi -- > > > > On Thu, 8 Jul 2004, Charles Comstock wrote: > > > > > Mauricio Fern�ndez wrote: > > > > > > > On Wed, Jul 07, 2004 at 04:22:36PM +0900, Charles Comstock wrote: > > > > > > > >>Why does this happen? > > > >> > > > >>class A > > > >>end > > > >> > > > >>A == A #1 => true > > > >>A === A #2 => false > > > >> > > > >>But 2 doesn't make any sense to me, why doesn't an A match another A? > > > >>Is this just something that slipped through or is there a specific > > > >>reason for this? > > > > > > > > > > > > A is not an instance of A; see the ri info for Module#===. > > > > > > > > > > At what point does it cause trouble for it to also return true if the > > > class matches? > > > > At the point where you call it :-) It can't do both; there would be no > > way to interpret the result: > > > > case s > > when String ... # what do you do here? print it? instantiate it? > > > > Sorry perhaps I didn't word my question well. I meant when does it cause a > problem for a class x to match itself? What code fails if A === A results in > true? Why would you ever want to match the descendents and instances of A but > not match A itself. It doesn't match the descendants of A, but rather instances of the descendants of A: irb(main):001:0> class A; end; class B < A; end => nil irb(main):002:0> case A irb(main):003:1> when B: puts "yes" end => nil irb(main):004:0> case B irb(main):005:1> when A: puts "yes" end => nil irb(main):006:0> case B.new irb(main):007:1> when A: puts "yes" end yes It's really the same test as #is_a? The docs should probably add an "of": Returns true if anObject is an instance of mod or of one of mod's descendents. David -- David A. Black dblack@wobblini.net