-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Inheritor provides a means to store and inherit data along the class hierarchy. An inheritor creates two methods, one named after for the key that provides a reader, and one named key! which provides the writer. Because of the unique nature of Inheritor, the reader cannot be used to modify the underlying store b/c it is a calculated attribute, thus any modifications to the result would not be passed on to the descendants.
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, as opposed to copying the parents variable value upon class creation or some other specific trigger.
- Create inheritable attributes.
- Works with modules, providing module method inheritance.
- Easily handles any data and inheritance type.
To create an inheritable class variable provide the #inheritor method with the name of the variable, it’s initial value, and the methdod to be used to process inheritance from descendant to descendant.
class X
inheritor :foo, [], :+
end
class Y < X
end
X.x! << :a
X.x => [:a]
Y.x => [:a]
Y.x! << :b
X.x => [:a]
Y.x => [:a, :b]
To install with RubyGems simply open a console and type:
$ gem install inheritor
Local installation requires Setup.rb (gem install setup), then download the tarball package and type:
$ tar -xvzf inheritor-1.0.0.tgz $ cd inheritor-1.0.0 $ sudo setup.rb all
Windows users use ‘ruby setup.rb all’.
(MIT License)
Copyright © 2004 Thomas Sawyer
This program is ditributed unser the terms of the MIT license.
See LICENSE or COPYING file for details.