From: "Ara.T.Howard" Date: 2003-10-02T13:45:16+09:00 Subject: Re: mixing in class methods On Thu, 2 Oct 2003, Gavin Sinclair wrote: > It sometimes makes me wonder why Ruby differentiates between instance > variables and class variables. The latter seem exceptional, for a number of > reasons. ~/eg/ruby > cat classvar.rb class A @@a = 42 # i am a class var, and can be inherited @a = 42 # i belong to THIS instance of a class, class A end class B < A printf "@@a = <%s>\n", (@@a or 'nil') printf "@a = <%s>\n", (@a or 'nil') end ~/eg/ruby > ruby classvar.rb @@a = <42> @a = -a ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ara.t.howard@noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 | The difference between art and science is that science is what we understand | well enough to explain to a computer. Art is everything else. | -- Donald Knuth, "Discover" | ~ > /bin/sh -c 'for lang in ruby perl; do $lang -e "print \"\x3a\x2d\x29\x0a\""; done' ====================================