Re: Class Level Variables
German Monfort <monfort.german <at> gmail.com>
2007-05-01 01:32:31 GMT
El Lunes, 30 de Abril de 2007 19:15, Gary Wright escribió:
> On Apr 30, 2007, at 1:52 PM, German Monfort wrote:
> >> 2) Class variables are associated with a class *and* its subclasses
> >> and the order of initialization is important.
> >>
> >> class C
> >> <at> <at> foo = 42 # shared by C and its decendents!
> >> def foo
> >> <at> <at> foo # shared with C, D, and E
> >> end
> >> def bar
> >> <at> <at> bar # this is C's <at> <at> bar
> >> end
> >> end
> >>
> >> class D < C
> >> end
> >>
> >> class E < C
> >> <at> <at> foo = 43 # <at> <at> foo shared with C, D, and E
> >> <at> <at> bar = 44 # <at> <at> bar only defined for E
> >> def bar
> >> <at> <at> bar # this is E's <at> <at> bar
> >> end
> >> end
> >>
> >> puts D.new.foo # 43
> >>
> >> puts E.new.bar # 44
> >> puts C.new.bar # undefined!
(Continue reading)