Archived. This functionality is available in Ruby Facets as
Module#class_inheritor. This repository is preserved for historical reference.
Inheritor provides a means to store and inherit data along the class
hierarchy. An inheritor creates two methods, one named after the
key that provides a reader, and one named key! which provides
the writer.
The most notable feature of Inheritor is that it is dynamic. Unlike other
solutions, such as ActiveSupport's class_inheritable_accessor, Inheritor
dynamically generates the inherited value whenever the reader is called.
class X
inheritor :foo, [], :+
end
class Y < X
end
X.foo! << :a
X.foo #=> [:a]
Y.foo #=> [:a]
Y.foo! << :b
X.foo #=> [:a]
Y.foo #=> [:a, :b]Copyright (c) 2004 Thomas Sawyer
MIT License. See LICENSE file for details.