From: Daniel Carrera Date: 2003-08-01T07:12:19+09:00 Subject: Re: Extracting a parent class Oh, sorry. In that case I don't imagine it's possible by default because in general there might not be an "obvious" way to turn class B into class A. You should make a B#to_A method. Cheers, Daniel. On Fri, Aug 01, 2003 at 07:09:07AM +0900, Michael Garriss wrote: > Sorry...I should have been more clear. While this works it does not > mantain the state. I would like all the members of 'b' that are class > A members to be set in 'a'. > > Daniel Carrera wrote: > > >Answer: > >a = b.class.superclass.new > > > >Why: > >b.class == B > >b.class.superclass == A > >b.class.superclass.new == A.new > > > >Cheers, > >Daniel. > > > >On Fri, Aug 01, 2003 at 06:53:01AM +0900, Michael Garriss wrote: > > > > > >>Sorry about the newbie question but.... > >> > >>class A > >>attr_accessor :a > >>end > >> > >>class B < A > >>attr_accessor :b > >>end > >> > >>b = B.new > >>b.a = "some data" > >>b.b = "some more data" > >>a = b.????? > >> > >>How do I set 'a' from 'b' so that a is of class A and not class B? I > >>don't want the extra info, I want just the subset of members found in > >>the parent class. Is there a way to cast? > >> > >>TIA > >>Michael Garriss > >> > >> > >> > > > > > > > > -- Daniel Carrera | PGP: 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88 Math PhD. UMD | http://www.math.umd.edu/~dcarrera/pgp.html * * * * * Weekly Smile * * * * * * * * * * * * * * * * * * * * * * * * Sign in a hotel in Athens: Visitors are expected to complain at the office between the hours of 9 and 11 A.M. daily. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *