From: Jamis Buck Date: 2005-02-24T02:37:01+09:00 Subject: Re: surprising: class A; end; A === A ==> false On 02:22 Thu 24 Feb , Jason Bailey wrote: > I'm thinking you can get what you want by > > case t > when A.class then... > when B.class then... > end > > since you want to compare the actual class of the object The problem is that A.class == B.class == Class. Apparently, the case statement is really just not designed for comparing class objects. - Jamis > > -------- Original Message -------- > > Subject: surprising: class A; end; A === A ==> false > > From: "Sam Roberts" > > Date: Wed, February 23, 2005 11:24 am > > To: "ruby-talk ML" > > > > I'm used to thinking of === being MORE useful > > On thinking about it, I can see why: in A === A, A is of class Class, > > and that class is not derived from the class A, so comparison is > > false... > > > > But this causes me some trouble, because there is no way to use > > case statements with a class: > > > > class A > > Ordinal = 1 > > end > > class B > > Ordinal = 2 > > end > > > > t = A > > > > case t > > when A then ... > > when B then ... > > end > > > > No case will ever match! > > > > Is my only way: > > > > if t == A > > ... > > elsif t == B > > ... > > elsif > > ..... > > > > or is there some clever workaround? > > > > I thought of > > > > t = A > > > > case t.new > > when A then ... > > > > > > But in my case, A and B actually have initialize methods, and they > > require args (different args). > > > > > > Thanks, > > Sam > > > > -- > > Sam Roberts > > -- Jamis Buck jamis_buck@byu.edu http://jamis.jamisbuck.org ------------------------------ "I am Victor of Borge. You will be assimil-nine-ed."