statichash.rb

Path: lib/hashery/statichash.rb
Last Update: Wed Feb 09 10:52:11 +0000 2011

StaticHash

A Hash object which raises an error if any previously-defined key attempts to be set again.

Synopsis

  foo = Hash::Static.new
  foo['name'] = 'Tom'    #=> 'Tom'
  foo['age']  = 30       #=> 30
  foo['name'] = 'Bob'

produces

  ArgumentError: Duplicate key for StaticHash -- 'name'

Credit

StaticHash has it‘s orgins in Gavin Kistner‘s WriteOnceHash class found in his +basiclibrary.rb+ script.

[Validate]