From: "Darryl L. Pierce" Date: 2011-10-21T05:40:18+09:00 Subject: Re: inheritance in ruby On 10/19/2011 09:16 AM, salamond wrote: > Hi, all. > > I'm creating an automation framework, and met this inheritance > private/protected problem. > Say I'm having SshCon and LinuxSshCon > class SshCon > def connect > cmd() > end > def cmd > end > def search > cmd("") > end > end > > class LinuxSshCon < SshCon > def cmd > format() > super() > end > end > > lsc = LinuxSshCon.new > lsc.connect # here it would use the cmd in LinuxSshCon, and cause me > some trouble > lsc.cmd I agree with another poster on this thread: the above has serious code stink. Why does LinuxSshCon override cmd() if that is a problem for the parent class? It seems that what cmd() is doing in your LinuxSshCon class needs to be split up into one or more additional methods. > My problem is this: > When I overwrite a method in sub class, is there a way I can keep the > original class calling its own method? > I tried > def connect > self.cmd > end > or use private/protected to claim cmd, none of them works Go back and revisit your design. If the method ON the base class should only invoke the base class method then your child shouldn't be overriding it. -- Darryl L. Pierce http://mcpierce.multiply.com/ "What do you care what people think, Mr. Feynman?"