Class: Hashery::StaticHash

### Home Classes Methods

### In Files

- lib/hashery/static_hash.rb

### Parent

Hashery::CRUDHash

### Methods

- #store

### Files

- LICENSE.txt
- NOTICE.txt

### Class/Module Index

Quicksearch

- Hashery
- Hashery::Association
- Hashery::Association::Kernel
- Hashery::CRUDHash
- Hashery::CastingHash
- Hashery::Dictionary
- Hashery::FuzzyHash
- Hashery::IniHash
- Hashery::KeyHash
- Hashery::LRUHash
- Hashery::LinkedList
- Hashery::LinkedList::Node
- Hashery::OpenCascade
- Hashery::OpenHash
- Hashery::OrderedHash
- Hashery::PathHash
- Hashery::PropertyHash
- Hashery::QueryHash
- Hashery::Stash
- Hashery::StaticHash
- Hash

No matching classes.

# Hashery::StaticHash

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

    foo = StaticHash.new
    foo['name'] = 'Tom'    #=> 'Tom'
    foo['age']  = 30       #=> 30
    foo['name'] = 'Bob'

produces

    ArgumentError: Duplicate key for StaticHash -- 'name'

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

TODO: Maybe StaticHash isn't bets name for this class?

### Public Instance Methods

store(key, value) click to toggle source

Set a value for a key. Raises an error if that key already exists with a different value.

key - Index key to associate with value. value - Value to associate with key.

Retruns value.

    # File lib/hashery/static_hash.rb, line 31
    def store(key, value)
      if key?(key) && fetch(key) != value
        raise ArgumentError, "Duplicate key for StaticHash -- #{key.inspect}"
      end
      super(key, value)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.