# \[ANN\] SuperHash

**URL:** <https://rubytalk.org/t/ann-superhash/2039>\
**Category:** ruby-talk\
**Created:** [28 September 2002 04:53 UTC](https://rubytalk.org/t/ann-superhash/2039 "2002-09-28T04:53:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [28 September 2002 04:53 UTC](https://rubytalk.org/t/ann-superhash/2039/1 "2002-09-28T04:53:41Z")

</div>

OK, it’s a corny name, but I’m open to suggestions…

A SuperHash is a hash-like object which can inherit key-value pairs from  
parent hashes. It can also have its own key-value pairs, which override  
inherited pairs. From the documentation:

The Ruby inheritance system is a powerful way to organize methods and  
constants in a hierarchy of classes and modules. However, it does not  
provide an easy way to organize inherited attribute values in such a  
hierarchy. A class variable is stored in the base class in which it  
was defined; its value can be changed by a subclass, but that change  
propagates to all subclasses of the base class. A class instance  
variable can take on a different value in each subclass, but there is  
no inheritance mechanism; its value is privately accessible by its  
owner, and does not propagate to subclasses.

SuperHash solves this class attribute problem and in addition is a  
general mechanism for defining attribute inheritance structures among  
objects of any type, not just classes. An example of the former is  
StateObject, in examples/state-object.rb. An example of the latter is  
AttributedNode defined in examples/attributed-node.rb…

It’s on RAA and at [http://redshift.sourceforge.net/superhash](http://redshift.sourceforge.net/superhash), and comes  
with tests and documentation.
