am i the only one suprised by this?
~/eg/ruby > cat class_vars.rb class A class << self def x= value @@x = value end def x @@x end end end class B < A; end A.x = 'forty-two' B.x = 42 p A.x p B.x class A class << self def x= value @x = value end def x @x end end end A.x = 'forty-two' B.x = 42 p A.x p B.x ~/eg/ruby > ruby class_vars.rb 42 42 "forty-two" 42
i see it, but don’t believe it… is it correct to say that:
iff you want a subclass to have it’s own copy of a ‘class var’ - use instance vars
- by ‘class var’ i mean not an instance var. obviously there are two
i don’t know how i made it this long without that biting me, doh!
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: http://www.ngdc.noaa.gov/stp/
TRY :: for l in ruby perl;do $l -e “print “\x3a\x2d\x29\x0a””;done