Jari Williamsson
2/6/2008 12:08:00 PM
tho_mica_l wrote:
>> The @@my_data syntax seems to attach only to the original class in which
>> it was defined, not for any subclasses.
>
> You can use attributes (@var) at the class level and manually copy
> values with the Class#inherited method.
>
> class A
> class << self
> attr_accessor :foo
> def inherited(sub)
> sub.foo = @foo
> end
> end
> self.foo = 1
> end
>
> class B < A
> end
>
> p A.foo, B.foo
> # => [1, 1]
> B.foo = 2
> p A.foo, B.foo
> # => [1, 2]
>
> If something like this is what you were asking for.
Thanks! This was what I was looking for!
> Or you could use some package that does this for you. IIRC traits
> implements such a thing.
I'll look at it as well!
Best regards,
Jari Williamsson