Path: | lib/more/facets/inheritor.rb |
Last Update: | Tue Oct 28 06:39:06 -0400 2008 |
Inheritor providse a means to store and inherit data via the class heirarchy. An inheritor creates two methods one named after the key that provides a reader. And one named after key! which provides the writer. (Because of the unique nature of inheritor the reader and writer can‘t be the same method.)
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]
It is interesting to note that the only reason inheritor is needed at all is becuase Ruby does not allow modules to be inherited at the class-level, or conversely that the "class-levels" of classes are not modules instead.
Copyright (c) 2005 Thomas Sawyer
Ruby License
This module is free software. You may use, modify, and/or redistribute this software under the same terms as Ruby.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.