From: Jason Bailey Date: 2005-02-24T02:22:37+09:00 Subject: Re: surprising: class A; end; A === A ==> false 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 > -------- 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