From: David Colque Date: 2008-08-27T00:19:25+09:00 Subject: Re: Access to method in superclass RichardOnRails wrote: > On Aug 25, 2:35 pm, David Colque wrote: >> LIKE ACCEDING TO THE METHOD " setSpeed" OF THE SUPERCLASS "Airplane". >> Thak you >> >> Attachments:http://www.ruby-forum.com/attachment/2606/prueba1.rb >> >> -- >> Posted viahttp://www.ruby-forum.com/. > > Hi David, > > Your access to Airplane::setSpeed is working. > > On line 55, you create an Airplane::Jet instance with @speed=0 > On line 56, you invoke that setSpeed on the instance with argument 422 > so the method on line 38 is called with 422 > which in turn invokes Airplane::setSpeed with the argument > 422*Multiplier, of 844, > which is then set in @speed of the Airplane::Jet instance > On line 57, you print out the 844 > > Then on line 57, you invoke > > Line 56 set the Jet's speed to 0 > Line 57 with argument 422 set the Jet's speed to 422*Multiplier, or > 844 and printed it > > Line 60 invoked accelerate, which in turn invoked > Line 45 setSpeed(getSpeed()*2) > getSpeed returned your 844, which then got doubled to 1688 > which was used as the argument to setSpped, which applied the > Multiplier > so the speed was set to 3376 > Line 61 used getSpeed to retrieve the 3376, which then got printed. > > All this is confirmed by lines 2 and 2 of your output. > > HTH, > Richard class Jet < Airplane MULTIPLIER = 2 def initialize super end def setSpeed(speed) super(speed*MULTIPLIER) end def accelerate # TROUBLE!!!!!!!! # LIKE ACCEDING TO THE METHOD " setSpeed" # OF THE SUPERCLASS "Airplane" Airplane::setSpeed(getSpeed()*2) end end At the time of making it run it leaves the error >ruby prueba1.rb prueba1.rb:28:in `accelerate': undefined method `setSpeed' for Airplane:Class (NoMethodError) from prueba1.rb:43:in `principal' from prueba1.rb:57 212 844 >Exit code: 1 -- Posted via http://www.ruby-forum.com/.