From: "Hal E. Fulton" Date: 2003-08-01T07:01:11+09:00 Subject: Re: Extracting a parent class ----- Original Message ----- From: "Michael Garriss" To: "ruby-talk ML" Sent: Thursday, July 31, 2003 4:53 PM Subject: Extracting a parent class > 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? I don't know of a simple, direct way to do this. Offhand it's possible that you're thinking in a C++ fashion and should simply do it another way. You *could* add a class method for B that would create an instance of A and return it... class B def B.to_A x = A.new x.a = self.a x end end That's consistent with the ordinary principles of an object knowing how to convert itself and a child class having knowledge of a parent but not vice versa. Hal -- Hal Fulton hal9000@hypermetrics.com