From: ahoward Date: 2002-12-05T00:10:31+09:00 Subject: Re: Class variables problem On Wed, 4 Dec 2002, Useko Netsumi wrote: > Why would the following did not work? > > class Test > def Calc(x) > return @rate*x > end > end > > class Fred < Test > @rate = 10 > end > > puts Fred.Calc(12) this has been called like a class method, but Calc is an instance method. additionally Calc should not be capitalized, else it is also a constant. finally, @rate is not set in an instance method, so it is not an instance variable (think about what self is outside of any instance methode, but inside a class definition - self == Class) try class Test def calc(x) return @rate * x end end class Fred < Test def initialize @rate = 10 end end fred = Fred.new puts fred.calc 12 >> 120 -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================